Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Large Text file(1GB-10GB) Java Swing

  1. #1
    Member
    Join Date
    Oct 2010
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

     
        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


  2. #2
    Member
    Join Date
    Oct 2010
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default 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

  4. #4
    Member
    Join Date
    Mar 2011
    Location
    Earth!
    Posts
    77
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default 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.

  5. #5
    Member
    Join Date
    Oct 2010
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Large Text file(1GB-10GB) Java Swing

    someone mentiond to me that the FileChannel class would do the job

Similar Threads

  1. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  2. [SOLVED] Parsing a text file in java
    By tccool in forum What's Wrong With My Code?
    Replies: 13
    Last Post: November 16th, 2010, 04:23 AM
  3. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM
  4. java.net.HttpURLConnection:large file to upload
    By tommy_725 in forum Java Networking
    Replies: 1
    Last Post: October 28th, 2009, 11:53 AM
  5. exception while Read very large file > 300 MB
    By ps.ganesh in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: June 11th, 2009, 11:39 PM