publicclassReadTxtFile{publicstaticvoidmain(Stringarg[]){InputStreamReaderread=null;try{Filefile=newFile("E:\\aaa.txt");//文件位置if(file.isFile()&&file.exists()){read=ne...
public class ReadTxtFile {
public static void main(String arg[]) {
InputStreamReader read = null;
try {
File file = new File("E:\\aaa.txt");// 文件位置
if (file.isFile() && file.exists()) {
read = new InputStreamReader(new FileInputStream(file));
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
String name = null;
String[] temp2 = null;
System.out.println("文件中的内容如下:");
while (lineTXT != null) {
System.out.println(lineTXT);
temp2 = lineTXT.split(",");// 从文件中读取的数据按,进行分割
lineTXT = bufferedReader.readLine();
}
while ((lineTXT = bufferedReader.readLine()) != null) {
// System.out.println("取得所有内容->" + lineTXT);
temp2 = lineTXT.split(",");
name = temp2[1];
System.out.println("取得名字->" + name);
}
} else {
System.out.println("找不到指定的文件!");
}
} catch (Exception e) {
System.out.println("读取文件内容操作出错");
e.printStackTrace();
} finally {
try {
read.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
展开