• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

DataOutputStream class

 
Ranch Hand
Posts: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

this codes writes this in the file :

hello h e l l o


i am confused why their is space between letters of hello when it is being written by writeChars();
documentation says :
writeChar(int v)
Writes a char to the underlying output stream as a 2-byte value, high byte first.
writeChars(String s)
Writes a string to the underlying output stream as a sequence of characters.
correct me if i am guessing it wrongly. writeChars() is converted as a sequence of character and char are written to outputstream as a 2-byte value, so one byte it covered by one letter(h,e,l,l,o) and 2nd byte byte the empty space ?
 
Marshal
Posts: 27371
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, if you only write characters which are in the first 256 positions in Unicode then that's what you're going to see. But the bytes between the visible characters aren't "empty space", they are actually null bytes (binary zero, that is). Get out your hex editor and use it to look at your output file and you'll see what I mean. Then try the code with some characters which are outside that Unicode page and you'll see something different.

(And I don't see what this has to do with programmer certifications, since you didn't reference any cert exams, so I'm going to move this post to Java in General.)
 
Puspender Tanwar
Ranch Hand
Posts: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:. Get out your hex editor and use it to look at your output file and you'll see what I mean.


what is hex editor ?

Paul Clapham wrote:(And I don't see what this has to do with programmer certifications, since you didn't reference any cert exams, so I'm going to move this post to Java in General.)


yes, its out of programmer certifications. I was just playing with the methods and noticed that there are two methods to write string, so i tried to figure out the difference between them
 
Sheriff
Posts: 22683
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Puspender Tanwar wrote:

Paul Clapham wrote:. Get out your hex editor and use it to look at your output file and you'll see what I mean.


what is hex editor ?


http://lmgtfy.com/?q=hex+editor
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic