Reading Bytes from a Text File
by , 01-13-2012 at 11:48 PM (1609 Views)
Java Code:package myPackage; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.io.Serializable; import java.lang.reflect.Array; import java.util.Scanner; public class TestClass implements Serializable { public static void main(String[] args) { File myFile = new File("c://try.txt"); FileInputStream myStream = null; try { myStream = new FileInputStream(myFile); } catch (FileNotFoundException e) { } int readBytes = 0; try { System.out.println(myFile.length()); byte[] myArray = new byte[(int) myFile.length()]; for(int i = 0; i<myArray.length; i++) { readBytes = myStream.read(); System.out.println(readBytes); } } catch (IOException e) { e.printStackTrace(); } } }










Email Blog Entry
License4J 4.0
05-22-2013, 12:23 AM in Java Software