File Handling

 avatar
unknown
java
a year ago
942 B
4
Indexable
package readfile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
import java.io.FileWriter;
public class Readfile 
{
    public static void main(String[] args) throws IOException
    {
        try
        {
            File obj=new File("theerdha2.txt");
            obj.createNewFile();
            FileWriter nw = new FileWriter("theerdha2.txt");
            nw.write("its a good file");
            Scanner sobj=new Scanner(obj);
            while(sobj.hasNextLine())
            {
                String data=sobj.next();
                System.out.println(data);
                sobj.close();
            }
        }
        catch(FileNotFoundException e)
        {
            System.out.println("file not found");
        }
        finally
        {
            System.out.println("file is successfully read");
        }
    }
    
}
Editor is loading...
Leave a Comment