FileReader

tech2024-10-17  1

简单代码完成写入操作

import java.io.File; import java.io.FileReader; import java.io.IOException; public class TestFileReader { public static void main(String[] args){ FileReader fr=null; try { File file=new File("D:\\mycode\\src\\pers\\wjx\\hello"); //最好写绝对路径,如果写相对路径就默认在我们 fr=new FileReader(file); int temp=fr.read(); while(temp!=-1){ System.out.print((char)temp); temp=fr.read(); } } catch (Exception e) { e.printStackTrace(); }finally { try { if(fr!=null)fr.close(); } catch (IOException e) { e.printStackTrace(); } } } }
最新回复(0)