`
kevin850115
  • 浏览: 64850 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

java读取txt文本

    博客分类:
  • Java
阅读更多
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class test1 {
	public String ReadDate() {
		String url = "D:\\2.txt";
		String strs = "";
		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();
				}
				return strs ;
			}

	public static void main(String a[])
	{
		test1 util = new test1();
		String cc = util.ReadDate();
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics