当前位置: 代码迷 >> Java相关 >> 打开文件
  详细解决方案

打开文件

热度:405   发布时间:2007-05-02 23:18:52.0
打开文件

用代码怎样实现在屏幕上显示打开文件的内容呀?不一定是文本文件!

搜索更多相关的解决方案: 文件  

----------------解决方案--------------------------------------------------------
可以用DOS命令type
也可以自己用IO来实现

----------------解决方案--------------------------------------------------------

char[] buf=new char[1024];
File f =new File("file.txt");
FileRaeder in =new FileReader (f);
int len=in.read(buf);
System.out.println(new String(buf,0,len));
或者
byte[] buf=new byte[1024];
File f =new File("file.txt");
FileInputStream in =new FileInputStream (f);
int len=in.read(buf);
System.out.println(new String(buf,0,len));

也行吧


----------------解决方案--------------------------------------------------------
我试试,谢谢
----------------解决方案--------------------------------------------------------
  相关解决方案