2016-10-17 2 views
0

は、ファイルと連携し、基本的なI/Oコードがあります:のJava I/Oファイルプログラム

:私はそれを実行しようとすると、

import java.io.File; 
import java.io.FileNotFoundException; 
import java.io.IOException; 
import java.io.PrintWriter; 
import java.util.Scanner; 

public class Main { 

public static void main(String[] args) throws FileNotFoundException { 
    File file = new File("test.txt"); 

    try { 

     PrintWriter output = new PrintWriter(file); 
     output.println("Testing"); 
     output.println("123"); 
     output.close(); 
    } catch (IOException ex) { 
     System.out.printf("ERROR: %s!\n", ex); 
    } 

    try { 
     Scanner input = new Scanner(file); 
     String message1 = input.nextLine(); 
     String message2 = input.nextLine(); 
     System.out.println(message1); 
     System.out.println(message2); 

    } catch (FileNotFoundException ex) { 
     System.out.printf("ERROR: %s!\n", ex); 
    }}}} 

は今、私は次のエラーを取得します

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at Main.main(Main.java:11)

これはなぜ起こるのでしょうか?

+0

どのようなコンパイルエラーが表示されますか? – Mureinik

答えて

2

構文エラーがあります。

中かっこの数が多すぎます。最後の最後の中括弧を取り除くと、あなたは行き​​たいです。

関連する問題