Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
929 B
0
Indexable
Never
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class fileio {
    public static void main(String[] args) {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt"));
            writer.write("Hello world ");
            writer.write("\n my name is sana ");
            writer.close();

        } catch (IOException e)

        {
            e.printStackTrace();
            // TODO: handle exception
        }
        try {
            BufferedReader reader = new BufferedReader(new FileReader("output.txt"));
            String l;
            while ((l = reader.readLine()) != null)
                System.out.println(reader.readLine());
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Leave a Comment