[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 7 KB, 248x169, Christopher-Michael-Langan.jpg [View same] [iqdb] [saucenao] [google]
6201265 No.6201265 [Reply] [Original]

why is this not printing? I want it to print to a text file that already has stuff in it and not overwrite it, but it's not writing anything at all.
public void openFile(String filename) throws IOException
{
outputFile = new PrintWriter(new FileWriter(filename, true));

}


public void writeToFile(Song song)
{
outputFile.println(song.getTitle());
outputFile.println(song.getArtist());
}


I'm calling the writeToFile method in a different class with the name of the Song object I want to use. It's supposed to print to a txt file but it isn't.

>> No.6201305

http://stackoverflow.com/questions/11496700/how-to-use-printwriter-and-file-classes-in-java

If the directory doesn't exist before you try to write the file, you need to make it. Remember to use outputFile.close().

Also >>>/g/ would probably be a little more helpful. It's a faster-moving board at least.

>> No.6201344

>>6201305
Thanks I figured it out now. I was stopping the program before it got to the close method lol.

>> No.6201362

>>6201265
<span class="math">\bf{JAVA~IS~NEVER~/SCI/~RELATED}[/spoiler]

gtfo

>> No.6201428

>>6201362
Why? Programing is a science, there is programming advice in the sticky.

>> No.6201430

>>6201305
no, all they would do is make fun of him for using java and then proceed to circle-jerk about C and Lisp