public void appendToFile(String str, String filename) throws Exception
{
// Open up an outputstream writer to the file, and append str to it.
FileOutputStream stream;//provides file access
OutputStreamWriter writer;//writes to the file
try
{
stream = new FileOutputStream(filename, true);
writer = new OutputStreamWriter(stream);
writer.write(str);
writer.close();
stream.close();
}//try
catch(Exception e)
{
throw e;
}//catch
}//appendToFile
{
// Open up an outputstream writer to the file, and append str to it.
FileOutputStream stream;//provides file access
OutputStreamWriter writer;//writes to the file
try
{
stream = new FileOutputStream(filename, true);
writer = new OutputStreamWriter(stream);
writer.write(str);
writer.close();
stream.close();
}//try
catch(Exception e)
{
throw e;
}//catch
}//appendToFile
public static void main(String[] args) {
try {
FileReader fr = new FileReader( "c:\\aaa.txt" );
String oldCon = "";
int c;
while ( (c = fr.read()) != -1 )
oldCon += (char)c;
fr.close();
FileWriter fw = new FileWriter( "c:\\aaa.txt" );
fw.write(oldCon);
fw.write("insert to the file end.");
fw.close();
} catch (Exception e) {
}
}
}