0
こんにちは皆私はjavaを初めて使用しています。なぜファイルが見つからないのかという問題が発生しています。私は、単にjfilechooserを使ってファイルを開き、ONE LINEテキストをオプションペインメッセージに出力するようにしています。何が間違っているか、何を修正する必要があるかに関するアイデア?ありがとうございますFileNotFound例外エラー
package synchro;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class SynchroTest {
public static void main(String[] args){
JFileChooser fileChooser = new JFileChooser();
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
System.out.println(selectedFile.getName());
try{
Scanner input = new Scanner(new File(selectedFile.getName()));
while(input.hasNext()){
String line = input.nextLine();
JOptionPane.showMessageDialog(null, "Input sentence:\n" + line);
}
}catch(FileNotFoundException e){
System.out.println("File Not Found");
}
}
}
}
なぜあなたはちょうど使用いけない - 'スキャナ入力は=新しいスキャナ(selectedFile);' –
私はエラーを取得します。 –
そのエラーは何ですか? –