• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

file output question

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this code simply takes 2 integer from user and write them on file, but the output file becomes rubbish such as:
how do i fix this? thanks


[edit]Add code tags. CR[/edit]
[ November 17, 2008: Message edited by: Campbell Ritchie ]
 
Marshal
Posts: 76055
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use the code button; I have edited your post so you can see how much easier it is to read.
You are not getting nonsense; when I edited your post I saw the squares had turned to tiny boxes which look like what I have called code, only smaller.That means you have put 0x0002 into your file, and 0x0002 is a control character. What it actually is, you can work out by looking for "basic Latin" or similar in Unicode. If you pass 2 you get 0x0002. Try running your app with 65 66 67 68 and see whether you get the same as 0x41 0x42 0x43 and 0x44 (same Unicode chart).

What is happening is that you are writing the numbers in binary rather than in text. You need to go through the classes you are using and see whether you are writing binary or text, and whether you should be using different classes. There is more about writing to files etc in the Java Tutorials; I think you want to write a "character stream."
 
Campbell Ritchie
Marshal
Posts: 76055
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually a trip to the DataOutputStream API will help explain things.
 
reply
    Bookmark Topic Watch Topic
  • New Topic