2014-11-14 3 views
0

안녕하세요. 저는 현재 4 개의 개별 텍스트 파일을 사용하고 메소드를 사용하여 하나에 결합하는 과제를위한 프로그램을 작성하려고합니다. 누군가이 코드를 잘못 이해했는지 궁금합니다.방법을 사용하여 텍스트 파일 결합하기

"Exception in thread "main" java.io.FileNotFoundException: wonder1.txt (The system cannot find the file specified) 
    at java.io.FileInputStream.open(Native Method) 
    at java.io.FileInputStream.<init>(Unknown Source) 
    at java.util.Scanner.<init>(Unknown Source) 
    at asig5.combineFile(asig5.java:26) 
    at asig5.main(asig5.java:17) " 

코드 : 프로젝트 위치 ~/Folder/MyProject 경우, 파일의 전체 경로 ~/Folder/MyProject/wonder1.txt 당신이 new File("wonder1.txt")을 쓸 때

import java.io.IOException; 
import java.io.PrintWriter; 
import java.io.File; 

public class asig5 { 

    public static void main(String[] args) throws FileNotFoundException { 

     PrintWriter newtext = new PrintWriter("wonder5.txt"); 
     File f0 = new File("wonder1.txt"); 
     File f1 = new File("wonder2.txt"); 
     File f2 = new File("wonder3.txt"); 
     File f3 = new File("wonder4.txt"); 
     combineFile(f0, newtext); 
     combineFile(f1, newtext); 
     combineFile(f2, newtext); 
     combineFile(f3, newtext); 

     newtext.close(); 

    } 

    public static void combineFile(File f0, PrintWriter output) throws FileNotFoundException { 
     Scanner input = new Scanner(f0); 
     while (input.hasNext()) { 

      String part1 = input.nextLine(); 
      System.out.println(part1); 
      output.print(part1); 
     } 

    } 
} 
+0

방금 ​​게시 한 로그로 무엇을 이해합니까? – Sufian

+0

파일을 찾을 수없는 이유를 알지 못합니다. –

+0

결합하려고하는 파일 * –

답변

0

는 의미 내가 그것을 실행하려고하면 나는이 다음 판독 오류 .

파일의 전체 경로를 제공하거나 파일을 프로젝트 폴더의 루트에 배치해야합니다.

+0

아 감사합니다! 그 말이 이제는 의미가 있습니다. –

관련 문제