On Windows the file's extension controls what program opens the file.
Did the same program open and display both the .txt and the.dat file?
Create a .txt file and rename it to .dat and see what happens.
Also rename a .dat to a .txt and see.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
if I use the file name as "primes.txt", the result is gibberish from beginning to end, but when I use "primes.dat", the result is what I want.
Are you saying that the exact same code, classes and methods, write different data when you change part of contents of a String from .dat to .txt ? And that is the ONLY change you make to the program.
Can you post the code where you define and use the file name?
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
Have you read the API doc for the write() method?
Try running your program and printing out the numbers as well as writing them to a file and compare what was printed with what is in the file.
The magic is what the compiler does with the number when you concatenate a String to it.
The int is converted to a String.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
now it doesnt work for .txt or .dat
How do you get it to fail?
It works fine for me. I get all readable numbers
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
There must have been some other change you made when changing the .dat to .txt. Or the other way.
That would NOT have any effect on what was written.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656