hi all,
i have the following code.when i print the file contents using BufferedReader iam getting the results properly. but when using DataInputStream for reading iam getting EOFException.Pls Help
the code is
import java.io.*;
public class IOTest {
private File f;
private FileInputStream fis;
private FileOutputStream fos;
IOTest(){}
IOTest(
String s)
{
try{
f = new File(s);
f.createNewFile();
fos = new FileOutputStream(f);
OutputStreamWriter os = new OutputStreamWriter(fos);
BufferedWriter bf = new BufferedWriter(os);
PrintWriter pw = new PrintWriter(bf);
pw.println("this is test");
pw.close();
bf.close();
os.close();
fos.close();
//f.close();
}catch(IOException e){
e.printStackTrace();
//System.out.println("IOTest:Usage IOTest filename");
}
}
public void readContents(){
try{
fis = new FileInputStream(f);
InputStreamReader is = new InputStreamReader(fis);
BufferedReader dis = new BufferedReader(is);
String str = dis.readLine();
System.out.println(str);
try{
DataInputStream ds = new DataInputStream(fis);
String s = ds.readUTF();
}catch(EOFException eof){
System.out.println("EOF Exception Caught");
eof.printStackTrace();
}
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String args[]){
IOTest io = new IOTest(args[0]);
io.readContents();
}
}