Demo09_FileReader.java 687 B

1234567891011121314151617181920212223242526272829
  1. package J20250725;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. /**
  6. * @author WanJl
  7. * @version 1.0
  8. * @title Demo09_FileReader
  9. * @description
  10. * @create 2025/7/25
  11. */
  12. public class Demo09_FileReader {
  13. public static void main(String[] args) throws IOException {
  14. FileReader fr=new FileReader("D:/我的文件.txt");
  15. int ch;
  16. // while ((ch=fr.read())!=-1){
  17. // System.out.print((char)ch);
  18. // }
  19. char[] chars=new char[1024];
  20. int length;
  21. while ((length=fr.read(chars))!=-1){
  22. System.out.println(new String(chars,0,length));
  23. }
  24. fr.close();
  25. }
  26. }