Large Text file(1GB-10GB) Java Swing
Hi Guys,
Right i am creating a program which is design to load up large text files in a jtextarea and allow the user to read through it and run a search, however it crashes my program when i open anything larger than 30mb file and even then the program is slow and unresponsive :(:( . Below is some of the code i am using
Code :
private void btnOpenFileActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFileChooser chooser= new JFileChooser();
chooser.showOpenDialog(this);
File file= chooser.getSelectedFile();
filePath=file.getAbsolutePath();
LoadFile loading= new LoadFile();
loading.setFile(file);
loading.start();
}
class LoadFile extends Thread {
// This method is called when the thread runs
File file;
public void run() {
FileReader input;
try {
txtStatus.setText("Loading......");
input = new FileReader(file);
txtPane.read(input, null);
txtStatus.setText("Done..");
} catch (Exception ex) {
}
}
public void setFile(File myFile){
file=myFile;
}
}
I have noticed a nice program called "large file viewer" it opens up these large files very quickly no laggyness or chunkiness of the interface and it works like a charm.
Do you know how i can achieve the same thing in java like opening up these large files quickly and not locking up ect ect.
Large Text File Viewer 5.2 - Features
Re: Large Text file(1GB-10GB) Java Swing
i have used the search filter and done endless google'n but still cant get my head around this
Re: Large Text file(1GB-10GB) Java Swing
The program isn't crashing, but probably throwing and OutOfMemoryError. You can increase the JVM memory, but for files that size might not do much good. You will probably have to read the file dynamically. You might consider writing your own Document, backed by a RandomAccessFile which reads the file dynamically. I've never done this before directly so I don't know if it will behave properly. I have however solve this issue myself by writing my own TextArea type components (don't ask why - long story) which are backed by Documents that dynamically read/write large data sets
Re: Large Text file(1GB-10GB) Java Swing
If you are going to load a 10 gb text file then you better have more then 10 gb ram. As copeg said, it is better to read it dynamically.
Re: Large Text file(1GB-10GB) Java Swing
someone mentiond to me that the FileChannel class would do the job