Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Outputting to files and deleting files

807580May 15 2010 — edited May 16 2010
I'm having a couple of little problems here. First, I'm trying to read from a file and then output to another file. I created a little setup that allows me to keep the information that's in the output file when the program runs again, rather than the normal issue of overwriting the file. However, when I do this, the program merges the ending line and beginning line on the same line. I want to perform a carriage return, or whatever it is, to go to the next line after the program writes to the file. I have the following code:
if(outputFile.exists()){

        istream = new FileInputStream(outputFile);
        ostream = new FileOutputStream(tempFile);
                    
         while((d = istream.read()) != -1){
              ostream.write(d);
         }

   ostream.write(10);
}
Now, the ostream.write(10); in theory is supposed to go to the next line in the text file after it copies over all the information. I outputted to the console each character that was copied over from one file to the next and determined that the number 10 was the what took it to the next line. However, it won't let me do that. It won't write the carriage return, but if I were to put, say a number 99 in there, it'll write the 'c' character. So what am I doing wrong?

Also, after I'm done with the temp file I would like to delete it. Using this general format
         //Create the object tempFile
     File tempFile = new File("TempFile.txt);

         //Create the file
     OutputStream ostream = new FileOutputStream(tempFile);

         //Delete the file
     tempFile.delete();
{code}

But that doesn't work, "TempFile.txt" stays on my computer. What am I doing wrong?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 13 2010
Added on May 15 2010
8 comments
221 views