fork download
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4.  
  5. public class Main {
  6. public static void main(String[] args) {
  7.  
  8. File file = new File("/etc/hosts");
  9. FileInputStream fis = null;
  10.  
  11. try {
  12. fis = new FileInputStream(file);
  13.  
  14. System.out.println("Total file size to read (in bytes) : "
  15. + fis.available());
  16.  
  17. int content;
  18. while ((content = fis.read()) != -1) {
  19. // convert to char and display it
  20. System.out.print((char) content);
  21. }
  22.  
  23. } catch (IOException e) {
  24. e.printStackTrace();
  25. } finally {
  26. try {
  27. if (fis != null)
  28. fis.close();
  29. } catch (IOException ex) {
  30. ex.printStackTrace();
  31. }
  32. }
  33.  
  34. }
  35. }
Success #stdin #stdout #stderr 0.04s 4386816KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
java.io.FileNotFoundException: /etc/hosts (No such file or directory)
	at java.io.FileInputStream.open0(Native Method)
	at java.io.FileInputStream.open(FileInputStream.java:195)
	at java.io.FileInputStream.<init>(FileInputStream.java:138)
	at Main.main(Main.java:12)