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