Skip to main content

Help with print writer method please

3 replies [Last post]
mrstevenfeldman
Offline
Joined: 2008-01-05
Points: 0

I am in AP COmputer Science and I am working on program that randomly generates the alphabet and then encrypts a word based on this alphabet. I have to output information to text file, but when ever I do, It overwrites the previous data.
Here is the section of code relating to my issue

PrintWriter outFile=new PrintWriter(new File("abcFile.txt"));
int keyNum=0;
while (file.hasNextInt())
{

keyNum=file.nextInt();
}
outFile.print((keyNum+1)+" ");
for(int x=0;x

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
aberrant
Offline
Joined: 2006-02-02
Points: 0

For UI code you can try the Java tutorial. http://java.sun.com/docs/books/tutorial/uiswing/

mrstevenfeldman
Offline
Joined: 2008-01-05
Points: 0

+message+" ");

outFile.println(newSentence);
outFile.close ();

Thanks for any and all help.
Also my course does go into user interface a lot, does any one know a good website to study on how to program user interfaces.

Thanks again, Feldman

Is it just my computer or part of it cut off?
above is the rest

tarbo
Offline
Joined: 2006-12-18
Points: 0

Consider using FileWriter instead. Its constructor has a parameter to have it append rather than overwrite:

[code]PrintWriter outFile = new PrintWriter(new FileWriter("abcFile.txt", true));[/code]