package CoreJavaPractice; import java.io.*; public class Practice_1 { public static void main(String[] args) throws IOException { readFile_3(); } public static void readFile_3() throws IOException { FileInputStream fis = new FileInputStream("FileStreamDemo.txt"); byte[] buf = new byte[fis.available()]; fis.read(buf); System.out.println(new String(buf)); fis.close(); } public static void readFile_2() throws IOException { FileInputStream fis = new FileInputStream("FileStreamDemo.txt"); byte[] buf = new byte[1024]; int len = 0; while((len=fis.read(buf))!=-1) { System.out.println(new String(buf,0,len)); } fis.close(); } public static void readFile_1() throws IOException { FileInputStream fis = new FileInputStream("FileStreamDemo.txt"); int ch = 0; while((ch=fis.read())!=-1) { System.out.println((char)ch); } fis.close(); } public static void writeFile() throws IOException { FileOutputStream fos = new FileOutputStream("FileStreamDemo.txt"); fos.write("abcde".getBytes()); fos.close(); } }