Tuesday, October 16, 2012

Read the entire File to a String

public class FileR {
   
    public static void main(String d[]) 
    {
        File file = new File("C:\\firstcontact\\HSRLOG.txt");
        Scanner scan = null;
        try
        {
                 scan = new Scanner(file);  
                 scan.useDelimiter("\\Z");  
                 String content = scan.next();
                 System.out.println(content);
       }
       catch(FileNotFoundException f)
       {
           System.out.println("File Not found Exception");
       }
       finally
       {
            scan.close();
       }
  }
   
}

No comments:

Post a Comment