aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes io question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "io question" Watch "io question" New topic
Author

io question

Abdul Latif
Ranch Hand

Joined: Jul 18, 2001
Posts: 89
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
You should certainly flush and close the output stream before attempting to read from the file.
Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
It worked fine for me. I am using jdk1.3 on win 98.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: io question