Hello,
Just follow the below code, this will help you , how you can use the input stream and the output stream.
Code:
class example
{
Public void write(String text)
{
String add = System.getProperty("user.dir") + "\\myfile.txt ";
try
{
FileWriter fwri = new FileWriter(add, true);
BufferedWriter up = new BufferedWriter(fwri);
up.write(text);
up.flush();
up.close();
}
catch(IOException ioe){System.out.System.out.println("Error:" + Ioe );}
}
Public void read()
{
try
{
String add = System.getProperty("user.dir") + "\\myfile.txt ';
FileReader fread = new FileReader(add);
BufferedReader br = new BufferedReader(en);
String text = "";
int a = 0;
while(a <2)
{
text = text + br.readLine() + "\ n";
a + +;
}
br.close();
returns null
System.out.System.out.println(text);
}
catch(IOException ioe){System.out.System.out.println("Error:" Ioe +);}
}
}
Bookmarks