세 개의 파일이 있다고 가정합니다 -
output1.txt
Hello how are you
output2.txt
Welcome to Tutorialspoint
output3.txt
We provide simply easy learning
Example
다음 Java 예제는 위 3가지 내용 files 대체 하나의 파일로 병합 -
import java.util.Scanner; public class MergingFiles { public static void main(String args[]) throws IOException { Scanner sc1 = new Scanner(new File("D://input1.txt")); Scanner sc2 = new Scanner(new File("D://input2.txt")); Scanner sc3 = new Scanner(new File("D://input3.txt")); FileWriter writer = new FileWriter("D://result.txt"); String str[] = new String[3]; while (sc1.hasNextLine()||sc2.hasNextLine()||sc3.hasNextLine()) { str[0] = sc1.nextLine(); str[1] = sc2.nextLine(); str[2] = sc3.nextLine(); } writer.append(str[0]+"\n"); writer.append(str[1]+"\n"); writer.append(str[2]+"\n"); writer.flush(); System.out.println("Contents added "); } }
output
Contents added
위의 세 파일이 동일한 파일에 직접 있는 경우 예제 프로그램을 -
example
import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class MergingFiles { public static void main(String args[]) throws IOException { //Creating a File object for directory File directoryPath = new File("D:\example"); //List of all files and directories File filesList[] = directoryPath.listFiles(); Scanner sc = null; FileWriter writer = new FileWriter("D://output.txt"); for(File file : filesList) { sc = new Scanner(file); String input; StringBuffer sb = new StringBuffer(); while (sc.hasNextLine()) { input = sc.nextLine(); writer.append(input+"\n"); } writer.flush(); } System.out.println("Contents added "); } }
output
Contents added로 다시 작성할 수 있습니다.
위 내용은 두 개 이상의 파일을 세 번째 파일로 교대로 병합하는 Java 프로그램의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!
성명
이 기사는 tutorialspoint에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
1 몇 달 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
1 몇 달 전By尊渡假赌尊渡假赌尊渡假赌
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
3 몇 주 전ByDDD
Windows 11 KB5054979의 새로운 기능 및 업데이트 문제를 해결하는 방법
2 몇 주 전ByDDD
Will R.E.P.O. 크로스 플레이가 있습니까?
1 몇 달 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

드림위버 CS6
시각적 웹 개발 도구

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는
