import java.io.*;
public class Test {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
FileWriter fw = new FileWriter("test.txt");
fw.write("dddd");//直接这样就行..他会自动转换为其Unicode编码..或者fw.write((int)c);强制转换一下也行
fw.append("wwwwww");
fw.flush();
fw.close();
FileReader fr = new FileReader("test.txt");
int ch = 0;
while((ch = fr.read())!=-1 )
{
System.out.print((char)ch);
}
}
}
【java】各种对文件,读写的方法及小例子
本文提供了一个使用Java进行文件读写的简单示例。通过创建FileWriter实例将字符串ddddwwwwww写入到名为test.txt的文件中,并利用FileReader从该文件中逐字符读取并打印所有内容。

被折叠的 条评论
为什么被折叠?



