| 1234567891011121314151617181920212223242526272829303132 |
- package course;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- /**
- * @author WanJl
- * @version 1.0
- * @title FileReaderTest
- * @description
- * @create 2026/8/7
- */
- public class FileReaderTest {
- public static void main(String[] args) throws IOException {
- FileReader fr=new FileReader("D:/abc.txt");
- //read () 读取一个字符
- // int ch;
- // while ((ch=fr.read())!=-1){
- // System.out.print((char) ch);
- // }
- //read (char[] c, int off, int len) 读取一部分字符数组
- char[] chars=new char[1024];
- int count;
- while ((count=fr.read(chars))!=-1){
- System.out.print(new String(chars,0,count));
- }
- //释放资源
- fr.close();
- }
- }
|