DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

File Concept

06.22.2011
| 1553 views |
  • submit to reddit
        // description of your code here

 import java.io.*;
 
public class Main {

     
    public static void main(String[] args)throws IOException
    {
            String path,fname;
            String dname;
            System.out.println("Enter the File name you want to be Read");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            fname = br.readLine();
            System.out.println("Enter the path");
            dname=br.readLine();
            path = dname+"/"+ fname;

            FileReader fr = new FileReader(path);
            String read;
            
            try {
            FileInputStream fStream = new FileInputStream(path);
            BufferedReader in = new BufferedReader(new InputStreamReader(fStream));
            while ((read=in.readLine())!=null) {
                System.out.println(read);
            }
            in.close();
            
        } catch (IOException e) {
            System.out.println("File input error");
        }
    }

}