标签:nal 基类 image 内存 tst 存在 写文件 种类 print
public int read() throws IOException{}
package day20; import java.io.File; import java.io.FileReader; import java.io.IOException; /** * 使用FileReader读取文件 */ public class FileReaderTest { public static void main(String[] args) { File file = new File("D:" + File.separator + "a.txt"); FileReader fileReader = null; try { fileReader = new FileReader(file); int ch; while (-1 != (ch = fileReader.read())) { System.out.print((char) ch); } } catch (Exception e) { e.printStackTrace(); } finally { if (null != fileReader) { try { fileReader.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
package day20; import java.io.File; import java.io.FileReader; import java.io.IOException; /** * 使用FileReader读取文件 */ public class FileReaderTest { public static void main(String[] args) { File file = new File("D:" + File.separator + "a.txt"); FileReader fileReader = null; try { fileReader = new FileReader(file); char[] buffer = new char[1024]; int len = 0 ; while (-1 != (len = fileReader.read(buffer))){ System.out.print(new String(buffer,0,len)); } } catch (Exception e) { e.printStackTrace(); } finally { if (null != fileReader) { try { fileReader.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
package day20; import java.io.File; import java.io.FileReader; import java.io.IOException; /** * 使用FileReader读取文件 */ public class FileReaderTest { public static void main(String[] args) { File file = new File("D:" + File.separator + "a.txt"); FileReader fileReader = null; try { fileReader = new FileReader(file); char[] buffer = new char[1024]; int len = 0 ; while (-1 != (len = fileReader.read(buffer))){ System.out.print(new String(buffer,0,len)); } } catch (Exception e) { e.printStackTrace(); } finally { if (null != fileReader) { try { fileReader.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
标签:nal 基类 image 内存 tst 存在 写文件 种类 print
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/11109472.html