This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Error recording Ascii file with PrintWriter  RSS feed

 
Fernando Skackauskas
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I have a program that has the following function:

- Receiving a string of 800 characters in Hex format, as below:

09dff751ac98c0925a2170de275a31c5462df93e08c1c086e7e277710a66408d01c38792c93819fbbd2bea9177896a2f2c15f7441353bfca30c1f4a97015294133f2e8cb7f4ebd2bfd79aebcb772305a6b1620a89e45344344064d55cff87adfaf026089f7fd3117176ce075cc00ef8279eee9cc782263be3ce4d3c5c88a68213941f4e2c3f6266450f0e0b87395d9677204edd52034c1feeaf2b4cb0d8b629f8dbd6310da4c0c532c1716485c898b4d08a9802947333df8e61195939d42a8605a86624c6db2a7a295417d9d5e6e320aeb7d97cb801ef4345fc745d9c651210c527e5731d1fb5ebff9091136ae338ca2845b2da7575590a496c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc28

- Convert this string to Ascii format.

- Record this string into one file "C:\\Nitgen\\biometria.rec".

The correct content of the recorded file should be as follows (the file is opened in the editor "Free Hex Editor Neo"):

.ß÷Q¬˜À’Z!pÞ'Z1ÅF-ù>ÁÀ†çâwq
f@Ç’É8û½+ê‘w‰j/,÷DS¿Ê0Áô©p)A3òèËN½+ýy®¼·r0Zk ¨žE4CDMUÏøz߯`‰÷ý1làuÌ


However, it is recording as a series of characters that is not being recognized, as follows:

.??Q???Z!p?'Z1?F-?>???wq
f@????8??+??w?j/,?DS??0???p)A3???N?+?y???r0Zk ??E4CDMU??z??`???1l?u?


Below the Java code:


What is wrong when the code records the file?

Thanks,

Fernando
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of the PrintWriter, you could use a FileOutputStream.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The output

.ß÷Q¬˜À’Z!pÞ'Z1ÅF-ù>ÁÀ†çâwq

does not look like containing ASCII characters. Something is not right with the requirement.
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that has the following function:

- Receiving a string of 800 characters in Hex format, as below:

09dff751ac98c0925a2170de275a31c5462df93e08c1c086e7e277710a66408d01c38792c93819fbbd2bea9177896a2f2c15f7441353bfca30c1f4a97015294133f2e8cb7f4ebd2bfd79aebcb772305a6b1620a89e45344344064d55cff87adfaf026089f7fd3117176ce075cc00ef8279eee9cc782263be3ce4d3c5c88a68213941f4e2c3f6266450f0e0b87395d9677204edd52034c1feeaf2b4cb0d8b629f8dbd6310da4c0c532c1716485c898b4d08a9802947333df8e61195939d42a8605a86624c6db2a7a295417d9d5e6e320aeb7d97cb801ef4345fc745d9c651210c527e5731d1fb5ebff9091136ae338ca2845b2da7575590a496c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc2896c1e98b7dbbcc28



I don't know if this will solve your problem but there is an important difference between the beginning of the requirements string and the one in your code.
 
Liutauras Vilda
Marshal
Posts: 4641
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fernando Skackauskas wrote:

And at some point, you possibly could suffer from exception related with index out of bounds.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!