读书人

【java】各种对资料读写的方法及小例

发布时间: 2012-09-28 00:03:35 作者: rapoo

【java】各种对文件,读写的方法及小例子

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);          }     }}


读书人网 >编程

热点推荐