• 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
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

io question

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
consider this code
import java.io.*;
public class DataStreamDemo1 {
public static void main (String args[]) {
try {
File f = new File("c:\\raftest\\Datatext.java");
FileInputStream fis = new FileInputStream(f);
FileOutputStream fos = new FileOutputStream(f);
DataInputStream dis= new DataInputStream(fis);
DataOutputStream dos= new DataOutputStream(fos);

dos.writeBoolean(true);
dos.writeUTF("the moving finger writes");

boolean b = dis.readBoolean();
String s = dis.readUTF();


System.out.println(b);
System.out.println(s);


}
catch (IOException e) {
System.out.println("cannot find the file");
}

}
}
This code writes aboolean & then writes a utf string. After writing it tries to read the boolean value with the readBoolean() & thentries to read the UTf sring with the readUTF().
the program only prints true & not the string. why ?
the readUTF() should read the string accroding to me. Can u please make things clear about UTf & unicode encoding. do the exam has questions on encoding
please help
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should certainly flush and close the output stream before attempting to read from the file.
 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It worked fine for me. I am using jdk1.3 on win 98.
 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic