Wednesday, August 14, 2013

Reading file using OneByte in java

import java.io.*;

public class OneByteTest4 {
public static void main(String[] args) throws Exception{
File f = new File("c:\\FileTest\\bbb.txt");
FileInputStream fis1 = new FileInputStream(f);
BufferedInputStream bis1 = new BufferedInputStream(fis1);
DataInputStream dis1 = new DataInputStream(bis1);

/*
int a = dis1.readInt();
double b = dis1.readDouble();
char c = dis1.readChar();
byte d = dis1.readByte();
byte e = dis1.readByte();

System.out.println("a = "+a);
System.out.println("b = "+b);
System.out.println("c = "+c);
System.out.println("d = "+d);
System.out.println("e = "+e);
*/
while(true){
int x = dis1.read();
if(x==-1) break;  //end of file

System.out.println("x = "+x);
}



}

}

No comments:

Post a Comment