首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java读取txt资料

2012-09-11 
java读取txt文件public class Utils {public static void main(String arg[]) {?try {?String encoding

java读取txt文件

public class Utils {

public static void main(String arg[]) {

?try {

?String encoding = "GBK"; // 字符编码(可解决中文乱码问题 )
??File file = new File("c:/accounts.txt");
??if (file.isFile() && file.exists()) {
??InputStreamReader read = new InputStreamReader(
??new FileInputStream(file), encoding);
??BufferedReader bufferedReader = new BufferedReader(read);
??String lineTXT = null;
??String [][] array = null;
??int count = 0;
??while ((lineTXT = bufferedReader.readLine()) != null) {
??String text = "";
??//用字符分隔成数组
??String str1 = lineTXT.replaceAll("\t","@");
??String[] str2 = str1.split("@");
??System.out.println("-----------");
??System.out.println(str2[0]+","+str2[1]+","+str2[2]+"");
??}
??read.close();
??}else{
???System.out.println("找不到指定的文件!");
??}
??} catch (Exception e) {
???System.out.println("读取文件内容操作出错");

??}
??}
}

热点排行