第1个回答 2011-11-13
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class IO {
public static void main(String[] args) throws IOException {
String str = "0,1,2,3,4,5,6,7,8,9 文件和输入输出流";//要写入文件内容
String file="D://myfile.txt";//文件地址(必须存在)
Input(file, str);
Output(file);
}
public static void Output(String file) throws IOException,
FileNotFoundException {
BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream(file), "GBK"));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
in.close();
}
public static void Input(String file, String str) throws IOException,
FileNotFoundException {
PrintWriter w = new PrintWriter(new OutputStreamWriter(
new FileOutputStream(file), "gbk"));
w.write(str);
System.out.println("input");
w.close();
}
}本回答被提问者采纳