我们的JAVA试题:将键盘输入的一行字符串在屏幕上显示,并将其添加到本地机文件F:\test.txt的尾部。

那位朋友帮个忙,我刚学JAVA

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class TestFile {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner san = new Scanner(System.in);
System.out.print("请输入:");
String str = san.nextLine();
FileWriter fw = null;
File f = new File("c:/file.txt");
fw = new FileWriter(f, true);
PrintWriter pw = new PrintWriter(fw);
pw.print(str);
pw.flush();
fw.flush();
pw.close();
fw.close();
System.out.println("成功!");
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-20
我也刚学JAVA
相似回答