Coming soon - Get a detailed view of why an account is flagged as spam!
view details
2
Having issues writing numbers to a .txt file; produces unintelligible symbols in the file and NEVER the numbers instructed
Post Body

I am trying to make code that can read a text file and write to it, and I'm having two issues. Here is a link to the code. I don't know what I am doing wrong, and need some guidance on what I could be doing better.

The main issue is when using my methods that write to the file, when I look at the actual .txt file it is NEVER the correct number, or even numbers at all. The only thing inside the text file after writing to it is random symbols that make no sense. I'm not sure why this is, I'm using data and file output streams and using the dos.writeInt method, but the numbers are never written to the file correctly. I don't get any errors from Java or anything indicating it is working incorrectly, so I would greatly appreciate any help. I am a beginner so it may be something I am not aware of.

Another issue I am having is none of my File x = new File("nameOfFile.txt") methods are creating a file. In order for the code to work I have to have already created a .txt file with the same name. Ideally, this program would just create a text file itself according to the code, but it does not. I have a previous project I did where I used the same exact method and that class did create a file, but here in this code it does not.

I've tried searching online and researched all the file creation and writing methods I could find, but nothing is working for me. Again, I'd really appreciate help to understand why this is happening and what I am doing wrong.

Author
Account Strength
100%
Account Age
9 years
Verified Email
Yes
Verified Flair
No
Total Karma
20,622
Link Karma
11,014
Comment Karma
8,746
Profile updated: 14 hours ago
Posts updated: 10 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago