读取文件中的内容将其显示出来

来源:互联网 发布:2016中国钢铁出口数据 编辑:程序博客网 时间:2024/05/16 14:05

 //读取文件中的内容将其显示出来
public class ReadFile{
 public static void main(String[] args) {
  
  int b;
  byte tom[] = new byte[1000];
  File file = new File("c://system.xml");
  try {
   FileInputStream f = new FileInputStream(file);
   
   b = f.read(tom,0,280);
   while(b!=-1){
    //StringBuffer str = new StringBuffer();
    String str = new String(tom,0,b);
    System.out.println(str);
    break;
   }
   
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}

原创粉丝点击