|
发表于 2021-12-4 19:45:37
|
显示全部楼层
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.Scanner;
- public class Main {
- static Scanner input = new Scanner(System.in);
- public static void main(String[] args) {
- while (true) {
- try {
- System.out.print("请输入文件路径及文件名:");
- String Filename = input.next();
- File f = new File(Filename);
- if (f.exists()) {
- FileInputStream in = new FileInputStream(f);
- int n;
- byte[] by = new byte[999999999];
- System.out.println("正在读取···");
- n = in.read(by);
- System.out.println(new String(by,0,n));
- }else {
- System.out.println("文件不存在。");
- continue;
- }}catch(FileNotFoundException e) {
- System.out.println("文件不存在或拒绝访问。");
- }catch(IOException e) {
- System.out.println("文件读写异常。");
- }
- }
- }
- }
复制代码 |
|