• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

not printing everything in data file

 
Marshal
Posts: 73981
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Chalkley wrote:. . . I wrote builder.append that didn't add to it?

I missed that part. Sorry for my mistake.

Don't know why you aren't appending the two Strings: print them out before appending.
How did you work out position? How do you know you are reading the right place in the file? What will happen if you try to read UTF from somewhere containing different sorts of data? If you return the byte[], have you put anything into it first? Open the file with a hexadecimal editor and see whether you can find the names in the file.
 
Campbell Ritchie
Marshal
Posts: 73981
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this supposed to be part of the same assignment? Is that how you created that file.dat file?

In which case I shall merge the two threads together and they will be in both fora, principally in the IO forum.

I tried your code, cut down to this:-and opened the file with hexedit chalkley/file.dat and this is what it contains:-Count the bytes; there are 27 of them (or more precisely 0x1b of them since all those numbers are in hexadecimal). If each dot represents a non‑word character, you shou‍ld be able to find the letters, particularly if you refer to this Unicode/ASCII table. You can also work out where they are. Remember what type of number you were writing and work out how many bytes they need in a file; remind yourself of the figures here.
Now, go back to the tutorials and see what it says about positions and how to find the next datum in such a file.
Also check the difference between the writeInt method and the write method.
 
Campbell Ritchie
Marshal
Posts: 73981
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now we have the two discussions together.

Whilst in the ASCII table, have a look at what 0x0004 or 0x04 means (I think it is ctrl‑D). Tell us what you have found out about positions and then let's try a bit more jiggery‑pokery.
 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Try putting an e.printStackTrace(); in there.  I bet you're getting an EOF error.  Our you putting the length of the string in the first two bytes?

Javadoc for readUTF() wrote:
Reads in a string from this file. The string has been encoded using a modified UTF-8 format.

The first two bytes are read, starting from the current file pointer, as if by readUnsignedShort. This value gives the number of following bytes that are in the encoded string, not the length of the resulting string. The following bytes are then interpreted as bytes encoding characters in the modified UTF-8 format and are converted into characters.

This method blocks until all the bytes are read, the end of the stream is detected, or an exception is thrown.

 
Master Rancher
Posts: 4465
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have merged your topic into this topic.


Where are the OPs posts?

Whoops.  Missed the page 2 link.  A problem with this site is that posts are not given id numbers.  If the top post on this page was not 1 then I'd quickly have known.
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page one.  Bottom right-hand corner. [edit] And top right-hand corner too.
 
Campbell Ritchie
Marshal
Posts: 73981
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:. . .

Javadoc for readUTF() wrote:. . .

Aaaaaaaaaaaaaaaaaah! And there I was thinking it was a delimiter for the preceding int, being equivalent to EOT.
 
Well THAT's new! Comfort me, reliable tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic