View RSS Feed

fatabass

Reading Bytes from a Text File

Rating: 1 votes, 1.00 average.
by , 01-13-2012 at 11:48 PM (2632 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();
		}
	}
}

Submit "Reading Bytes from a Text File" to Facebook Submit "Reading Bytes from a Text File" to Digg Submit "Reading Bytes from a Text File" to del.icio.us Submit "Reading Bytes from a Text File" to StumbleUpon Submit "Reading Bytes from a Text File" to Google

Tags: None Add / Edit Tags
Categories
Uncategorized

Comments