运用JAVA读取txt文件

package com.read;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author dengshaohua
 */
public class ReadPhone {

 /**
  * 读取数据
  */
 public void ReadDate() {
    String url = "D:/data.txt";
    try {
         FileReader read = new FileReader(new File(url));
         StringBuffer sb = new StringBuffer();
         char ch[] = new char[1024];
         int d = read.read(ch);
         while(d!=-1){
             String str = new String(ch,0,d);
            sb.append(str);
            d = read.read(ch);
          }
          System.out.print(sb.toString());
     } catch (FileNotFoundException e) {
          e.printStackTrace();
     } catch (IOException e) {
        e.printStackTrace();
     }
 }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2008-10-07 18:50  枣阳人在深圳  阅读(2620)  评论(0编辑  收藏  举报