java.io.FileNotFoundException-to read a file in java

In this Program i am going to read a file in java

Error Message:

Exception in thread "main" java.io.FileNotFoundException: c:\test.txt (The system cannot find the file specified)
       at java.io.FileInputStream.open0(Native Method)
       at java.io.FileInputStream.open(FileInputStream.java:195)
       at java.io.FileInputStream.<init>(FileInputStream.java:138)
       at java.io.FileInputStream.<init>(FileInputStream.java:93)
       at java.io.FileReader.<init>(FileReader.java:58)
       at com.lib.ReadaFile.main(ReadaFile.java:11)

Error Description:

In below red background line i gave wrong path,so I got an error.

package com.lib;

import java.io.FileReader;


public class ReadaFile
{
           public static void main(String args[])
          
                throws Exception  { 
                 FileReader fer = new FileReader("c:\\test.txt");   
                 int i;   
                 while((i=fer.read())!=-1)   
                 System.out.print((char)i);   
                 fer.close();   
           }   
}   




Error Solution:

package com.lib;

import java.io.FileReader;


public class ReadaFile
{
           public static void main(String args[])
          
                throws Exception  { 
                 FileReader fer = new FileReader("C:\\Users\\PRASANTH\\Desktop\\Prasanth.txt");   
                 int i;   
                 while((i=fer.read())!=-1)   
                 System.out.print((char)i);   
                 fer.close();   
           }   
}   



Output:

Welcome to Surya InfoWare
Share this post :

Post a comment

Please share your valuable feedback and share this article in social media.

 
Support : Ranga Rajesh Kumar
Copyright © 2019. Error Solution - All Rights Reserved
Site Designed by Ranga Rajesh Kumar