• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unicode

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q2
How many bytes does the following program write to temp.txt?
import java.io.*;
class TestIOApp
{
public static void main(String args[]) throws IOException
{
FileOutputStream fs=new FileOutputStream("test.txt");
String s="text";
for(int i=0;i<s.length();i++)>
fs.write(s.charAt(i));
fs.close();
}
}
(a)2 bytes
(b)4 bytes
(c)8 bytes
(d)16 bytes
The answer mentioned is (b).Should'nt it be (c) since each character is represented as 2 bytes(16 bits) ???
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It writes the low-order byte. Since each character is two bytes, and it writes only the low-order byte, it writes a total of four bytes.
Bosun
 
reply
    Bookmark Topic Watch Topic
  • New Topic