import java.io.*;

public class provefile
{
	public static void main (String args[])
	{
		writeFile();
		readFile();
	}	
	
	public static void writeFile ()
	{
		FileOutputStream fout;		
		try
		{
		    fout = new FileOutputStream ("prova2.txt");
		    PrintStream scrivi = new PrintStream(fout);
		    scrivi.println ("riga 1");
		    scrivi.println ("riga 2");
		    scrivi.println ("riga 3");
		    fout.close();		
		}
		catch (IOException e) { }	
	}
	public static void readFile ()
	{
		FileInputStream fin;	
		try
		{
		    fin = new FileInputStream ("prova2.txt");
		    DataInputStream filedaleggere = new DataInputStream(fin);
		    String rigaCorrente = "";
		    while(true)
		    {
		    	rigaCorrente = filedaleggere.readLine();
		    	if (rigaCorrente == null) break;
		    	System.out.println(rigaCorrente);
		    }
		    fin.close();		
		}
		catch (IOException e) { }
	}	

}