你就把这个代码改成这样就可以了吧?这个有多难?
你基础没学好,后面的内容基本上没办法学,返回前面去温故知新吧
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
public class main {
public static void output(String filename) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
String s; while((s = br.readLine()) != null) System.out.println(s);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
output(scanner.next());
}
}
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
public class main {
public static boolean output(String filename) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
String s; while((s = br.readLine()) != null) System.out.println(s);
} catch(Exception e) {
//e.printStackTrace();
return false;
}
return true;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入文件路径及文件名:");
while(!output(scanner.next())) {
System.out.print("文件不存在,请重新输入:");
}
}
}
|