素数を含むテキストфалйаからコンピューターの数を読み取る次のプログラムを作成しました
import java.io.*;
public class ReadFromFile {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int CountComputers=0;
try {
DataInputStream ConfigFile = new DataInputStream( new
FileInputStream("D:\\HadoopFolder\\ReadFromFile\\src\\countcomputers.txt"));
CountComputers=ConfigFile.readInt();
ConfigFile.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//CountComputers=ConfigFile.readInt();
System.out.println("Количество компьютеров равно "+CountComputers);
}
}
その結果、次のエラーを受け取りました
Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readInt(Unknown Source)
at ReadFromFile.main(ReadFromFile.java:16)
また、確かに質問があるかどうかは、ファイルからの読み取りを試して結論付ける必要があります...期待します(あるプロジェクトでは赤を強調し、他のプロジェクトではJavaで(他の種類でした)いいえ)。私はJavaの初心者ですので、ご理解の上での対応をお願い致します。