Java IO
Submitted by Ahmed Hashim on Sun, 2006-01-08 15:46.
To write to a file
try {
BufferedWriter out = new BufferedWriter(new FileWriter(
System.getProperty("user.dir")+
System.getProperty("file.separator") + "test2.txt"));
out.write("Testing IO using Random Access File");
out.close();
} catch (IOException e) {
e.printStackTrace();
}
and to read a file
try {
BufferedReader in = new BufferedReader(new FileReader(
System.getProperty("user.dir")
+ System.getProperty("file.separator") + "test2.txt"));
String str;
while ((str = in.readLine()) != null) {
System.out.print(str);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
__Useful links__
*[Reading and Writing..The Java Developers Almanac 1.4| http://javaalmanac.com/egs/java.io/pkg.html#Reading%20and%20Writing]





