public static void main(String[] args) { FileInputStream fis = null; try { fis = new FileInputStream("D:\\1.txt"); int len; while ((len = fis.read()) != -1){ System.out.println((char) len); } } catch (IOException e) { e.printStackTrace(); }finally { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } }
public static void main(String[] args) { try(FileInputStream fis = new FileInputStream("D:\\1.txt"); FileOutputStream fos = new FileOutputStream("D:\\2.txt")){ int len; while ((len = fis.read()) != -1){ System.out.println((char) len); } }catch (IOException e){ e.printStackTrace(); } }
public static void main(String[] args) throws FileNotFoundException { FileInputStream fis = new FileInputStream("D:\\1.txt"); FileOutputStream fos = new FileOutputStream("D:\\2.txt"); try(fis;fos){ int len; while ((len = fis.read()) != -1){ System.out.println((char) len); } }catch (IOException e){ e.printStackTrace(); } }
原文:https://www.cnblogs.com/csyzlm/p/14437176.html