public class InputStreamTest { public static void main(String[] args) { InputStream fis=null; try{ //2.创建文件输入对象 fis=new FileInputStream("D:\\doc\\test.txt"); System.out.println("可读取的字节数: "+fis.available()); //3.执行读操作 int data=0; //循环读取数据 System.out.println("文件的内容: "); while((data=fis.read())!=-1){ System.out.print((char)data+" "); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally { try{ if (fis!=null){ fis.close(); } } catch (IOException e) { e.printStackTrace(); } } } }
标签:文件,fis,System,printStackTrace,catch,data,输入,out From: https://www.cnblogs.com/max-hou/p/18448219