• 0

help with input reader


Question

[JAVA]

ok so i have this input reader code which works fine if you want it to out print to a console but i wanted it to output the data it read to a jtextarea in a gui in another class ive tryed everything no look :( wondering if anyone could help me? heres my code for my text reader:

import java.io.*;

public class FileInput {

	public void readFile(){
		File file = new File("num1.dat");
		FileInputStream fileInputStream = null;
		BufferedInputStream bufferedInputStream = null;
		DataInputStream dataInputStream = null;

		try {
			fileInputStream = new FileInputStream(file);

			bufferedInputStream = new BufferedInputStream(fileInputStream);
			dataInputStream = new DataInputStream(bufferedInputStream);

			// returns 0 when it has reached the end of the file
			while (dataInputStream.available() != 0) {
				   System.out.println(dataInputStream.readInt());
				}			  
			// closes the stream
			fileInputStream.close();
			bufferedInputStream.close();
			dataInputStream.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}

Thanks in advanced.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

u need to pass the text area into ur file input class..maybe as constructor arg. then do

textarea.setText((dataInputStream.readInt());

maybevpass file name and text area as ars to ur readFile() method.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.