Advertisement
gitman3

Simple read from file as it is

Jun 15th, 2023 (edited)
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.*;
  3.  
  4. class Main{
  5.     public static void main(String args[]){
  6.        
  7.         int n=0;
  8.         try{
  9.            
  10.             FileInputStream fis=new FileInputStream("D:\\doe\\code\\java\\File_Handling\\myfile.txt");
  11.             // FileOutputStream fos=new FileOutputStream("D:\\doe\\code\\java\\File_Handling\\output.txt");
  12.            
  13.             n=fis.read();
  14.            
  15.             while((n=fis.read())!=-1){
  16.                 System.out.print((char)n);
  17.             }
  18.            
  19.             fis.close();
  20.             // fos.close();
  21.        
  22.         } catch(Exception e){
  23.             System.out.println("EXCEPTION");
  24.         }
  25.        
  26.        
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement