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();
}
}
}
Question
masterhoulahan
[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