import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class File1 {
String name;
void readFile(){
Scanner sr = new Scanner(System.in);
while(true){
System.out.print("请输入一个TXT文件名:");
name = sr.nextLine();
File f = new File("C://"+name+".txt");
if(f.exists()){
String data;
try {
BufferedReader br = new BufferedReader(new FileReader("C://"+name+".txt"));
data = br.readLine();
while( data!=null){ //一次读入一行,直到读入null为文件结束
System.out.println(data);
data = br.readLine(); //接着读下一行
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
System.out.println("文件不存在");
}
}
}
public static void main(String[] args) {
new File1().readFile();
}
}
亲 是MATLAB啊 帮忙再看看?