Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Appending to a text file

$
0
0
public void recordObject()
	{
	
		File myFile = new File("history.txt");
		PrintWriter output = null;
		Scanner in = null;
		
		if(!myFile.exists())
		{
			// the file dosent exist
			try
			{
				myFile.createNewFile();
				// file created
			}
			catch (IOException e)
			{
				System.out.println("a error occured");
				System.exit(0);
			}
		}
		else
		{
			// file exists
			try
			{
				output = new PrintWriter(myFile);
			}
			catch (FileNotFoundException e)
			{
				System.out.println("Error with opening the file program closing");
				System.exit(0);
			}
			// file opened
			
			output.append("<<1>> new prosses");
			
			output.close();
			
		}




what have i done wrong in this method i am trying to append to the text file and for some reason it just keeps overwriting what i have in the file.

thanks dale

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>