我有一个关于太阳系和这段代码的作业,它只读取文本文件我需要代码来读取文件并将文本文件中的数据放到变量中,就像一个变量中的每一行一样
您可以更改代码但为我设置简单
fileName = "C:\\Users\\thkraa\\Documents\\NetBeansProjects\\SolarSystem\\src\\SolarSystem.in";
try {
//Create object of FileReader
FileReader inputFile = new FileReader(fileName);
//Instantiate the BufferedReader Class
bufferReader = new BufferedReader(inputFile);
String line;
// Read file line by line and print on the console
while ((line = bufferReader.readLine()) != null) {
}
System.out.println("The File Has Been Imported!!");
//Close the buffer reader
bufferReader.close();
} catch (Exception e) {
System.out.println("Error while reading file:" + e.getMessage());
}