Java 文件与 IO【复习备考简单练习 二】

版权声明:转载请注明出处,谢谢。 https://blog.csdn.net/Mercury_Lc/article/details/85300354

说明:仅仅用于复习备考 IO 与文件操作。

题目:从 C 盘的 test 中读取一个文件并输出到显示屏上。

package aaa;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Main {

	static String file = "C:\\test.txt";  //

	public static void main(String[] args) { // throws FileNotFoundException{ 别忘记异常处理

		try {
			FileInputStream fis = new FileInputStream(file);
			int eof = 0;
			while((eof = fis.read()) != -1) {
				System.out.print((char)eof);
			}
			fis.close();
		} catch (IOException ioe) {
			System.out.print("文件错误");
			System.exit(1);
		}
	}
}

猜你喜欢

转载自blog.csdn.net/Mercury_Lc/article/details/85300354