• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileOutputStream not writing to a file  RSS feed

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am using a FileOutputStream to write a file but it is not writing data to destination file from source

Here is my code



can any one find a bug where i am wrong why data is not on output file?


Thanks
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know nothing is written to the file? Those four bytes are non-displayed characters, so simply opening the file in a text editor probably wouldn't be proof that nothing was written.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

yes you are true

there is something displayed but they are not those values that I write on that file.


So how to read actual values?

any typecasting or else


 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try writing out these bytes: 74, 97, 118, 97
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

It works it prints

j a v a

Can you explain why this is happening?
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Text editors are designed to interpret a specific range of bit-patterns according to a character set... the bit-patterns of 74, 97, 118, 97 are mapped to the characters J, a, v, a according to the ASCII character set hence the reason for output...

To help you map certain characters to certain number-encodings you can refer to this table >> ascii table
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rico
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, if your intent is to write character output instead of binary output, you should use a Writer instead of an OutputStream. A FileWriter would be the closes analog, but a PrintWriter would work well here I think.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or a Formatter, but that will only write to text files.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!