ファイルから読み書きするプログラムがあります。でファイルを作成しようとしましたmain
が、それでも機能しません。
public static void main(String[] args) throws NumberFormatException,
IOException,
FileNotFoundException {
System.out.println("Work in progress");
File f = new File("Data.txt");
System.out.println(f.getAbsolutePath());
// Yes, it's there.
UI ui = new UI();
GenericDictionary<Integer> gd = new GenericDictionary<Integer>();
Repository repo = new Repository("Data.txt", gd);
// Should work, right ?
今私のリポジトリ:
public Repository (String fileName, GenericDictionary gd)
throws IOException,
NumberFormatException,
FileNotFoundException {
this.fileName = fileName;
this.gd = gd;
FileReader input = null;
BufferedReader inputBuffer = null;
try {
input = new FileReader(this.fileName);
inputBuffer = new BufferedReader (input);
String line;
while ((line = inputBuffer.readLine()) != null) {
String[] inputData = line.split(",");
Node<Integer> newNode = new Node<Integer> (
Integer.parseInt(inputData[0]),
Integer.parseInt(inputData[1]));
this.gd.add(newNode);
}
}catch (NumberFormatException nfe){
System.out.println(
"Repository could not load data due to NumberFormatException: "
+ nfe);
}catch (FileNotFoundException fnfe) {
System.out.println("File not found, error: " + fnfe);
}finally {
inputBuffer.close();
input.close();
}
}
これで、ファイルを作成しても、使用したくありません。最初はリポジトリのコンストラクターにありましたが、メインファイルに移動しましたが、それでも成功しませんでした。
これは、Eclipseがコンソール内で出力するものです。
- 進行中の作業D:\ Info \ Javaworkspace \ Laborator_4 \ Data.txtファイルが見つかりません、エラー:java.io.FileNotFoundException:Data.txt(システムは指定されたファイルを見つけることができません)スレッド"main"java.langで例外が発生しました。 main.app.main(app.java:23)のrepository.Repository。(Repository.java:49)でのNullPointerException