I am trying to read from a text file which of size 1 MB, and contains 5000 lines of data.
Following is the code of class which I am using to read from the file
public class PlayFile extends Timer implements ActionListener{
File filename;
BufferedReader out;
//float frameid,prev_frameid;
public PlayFile(File file, int interval)
{
super(interval,null);
FileInputStream fstream = null;
try {
filename = file;
fstream = new FileInputStream(file);
DataInputStream in = new DataInputStream(fstream);
out = new BufferedReader(new InputStreamReader(in));
this.addActionListener(this);
out.readLine();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
fstream.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public void actionPerformed(ActionEvent e)
{
try {
if(out.ready())
{
String br = out.readLine();
String[] inputfile = new String[69];
for(int i = 0;i<69;i++)
inputfile[i]= br.split("\t")[i];
for(int i = 0;i<69;i++)
System.out.print(inputfile[i]+" ");
System.out.println();
//playData(inputfile);
}
else
this.stop();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
It reads 25 lines of data and after that it starts giveing the following exception.
java.io.IOException: Read error
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:199)
at java.io.DataInputStream.read(DataInputStream.java:132)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at dynamicgraph.GPlot$PlayFile.actionPerformed(GPlot.java:817)
at javax.swing.Timer.fireActionPerformed(Timer.java:271)
at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
The only line no indiacted for my program in the error is
dynamicgraph.GPlot$PlayFile.actionPerformed(GPlot.java:817)
and this line contains the readLine() method to read the file. I am not able to guess the reason why does it stop reading after 25 lines