joseleonweb

Untitled

Feb 28th, 2021
733
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2.  
  3. public class ShowFile3 {
  4.  
  5.     public static void main(String[] args) {
  6.         int i;
  7.        
  8.         // First make sure that a file name has been specified.
  9.         if(args.length != 1) {
  10.             System.out.println("Usage: ShowFile filename");
  11.             return;
  12.         }
  13.        
  14.         // The following code uses try-with-resources to open a file
  15.         // and then automatically close it when the try block is left.
  16.        
  17.         try(FileInputStream fin = new FileInputStream(args[0])) {
  18.            
  19.             do {
  20.                 i = fin.read();
  21.                 if(i != -1) System.out.print((char) i);
  22.             } while(i != -1);
  23.            
  24.         } catch(IOException exc) {
  25.             System.out.println("I/O Error: " + exc);
  26.         }
  27.     }
  28. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×