-3
我有這個代碼我工作我可以從文件中讀取,但我不能保存答案我的txt文件。我怎麼回憶做其他操作相同的號碼。我需要提示如何做到這一點。如何讀取和寫入答案在文件I/O
package x;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class x {
public static void main(String args[]) throws FileNotFoundException {
//creating File instance to reference text file in Java
File text = new File("C:\\Users\\user\\Desktop\\testScanner.txt");
//Creating Scanner instnace to read File in Java
Scanner scnr = new Scanner(text);
//Reading each line of file using Scanner class
int lineNumber = 1;
while(scnr.hasNextLine()){
String line = scnr.nextLine();
int foo = Integer.parseInt(line);
System.out.println("===================================");
System.out.println("line " + lineNumber + " :" + line);
foo=100*foo;
lineNumber++;
System.out.println(" foo=100*foo " + lineNumber + " :" + foo);
}
}
}
你到目前爲止嘗試過什麼?請閱讀[this](http://stackoverflow.com/help/on-topic)以幫助您獲得更好的(也可能更快)答案。 – FlyingPiMonster 2014-12-05 02:15:10
如果您需要提示,請查看[FileWriter](https://docs.oracle.com/javase/7/docs/api/java/io/FileWriter.html) – Baby 2014-12-05 02:16:17