以及如何使fileReader将文件打印为Record1,即记录2。我希望编译器中的输出为Record 1:名称,地址,电话,然后下一行Record2等,等等
public class Lab8b {
public static void main(String[] args){
String fileName = "Info.txt";
Scanner User_Input=new Scanner(System.in);
try {
FileWriter fileWriter = new FileWriter(fileName);
BufferedWriter bufferedWriter = new
BufferedWriter(fileWriter);
System.out.println("Please enter your name: ");
bufferedWriter.write("Name: " +
User_Input.next());
System.out.println("Please enter your
address: ");
bufferedWriter.write(", Address: " +
User_Input.next());
System.out.println("Please enter your phone
no: ");
bufferedWriter.write(", Phone: " +
User_Input.nextInt());
bufferedWriter.newLine();
bufferedWriter.close();
String line = null;
FileReader fileReader = new
FileReader(fileName);
BufferedReader bufferedReader = new
BufferedReader(fileReader);
while ((line = bufferedReader.readLine()) !=
null) {
for(int i=0;i<=line.length();i++){
System.out.println("Record "+i+":
\n"+line);
}
}
bufferedReader.close();
}
catch(IOException ex){
System.out.println("Error in file reading");
}
}
}