Advertisement
joseleonweb

Untitled

Feb 27th, 2021
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1.         try {
  2.             // read bytes until End Of File is encountered
  3.             do {
  4.                 i = fin.read(); // Read from the file
  5.                 if(i != -1) System.out.print((char) i);
  6.             } while(i != -1); // When i equals -1, the EOF has been reached
  7.         } catch(IOException exc) {
  8.             System.out.println("Error reading file.");
  9.         } finally {
  10.             // Close file on the way out of the try block
  11.             try {
  12.                 fin.close(); // Close the file
  13.             } catch(IOException exc) {
  14.                 System.out.println("Error closing file.");
  15.             }
  16.         }
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement