The Artima Developer Community
Sponsored Link

Java Answers Forum
Eclipse 3.2 IO Problem

3 replies on 1 page. Most recent reply: Sep 13, 2006 11:13 PM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Jessica Reuter

Posts: 2
Nickname: jezzica85
Registered: Sep, 2006

Eclipse 3.2 IO Problem Posted: Sep 11, 2006 4:09 PM
Reply to this message Reply
Advertisement
Hi everybody!
I'm new here so I'll try to make this brief. I'm writing an application with Eclipse where I need to get information from multiple files, and I'll read them in one by one. My problem is, sometimes I can read in one file, sometimes I can't read in any, and I can never read in more than one. The application seems to freeze. All the files I've tested so far are very small, less than 10 kb. The biggest one I'd ever need to import at one time might be 50 kb. Is this a memory problem? because I'm 99% sure it's not a coding problem, and if it is a memory problem, can anyone help me out?
Thanks!
Jezzica85


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Eclipse 3.2 IO Problem Posted: Sep 11, 2006 11:09 PM
Reply to this message Reply
When you create file Objects, store them in an List
(ArrayList implementation). Opening and closing them
from there should be a breeze unless you have done
something wrong.

There is nothing wrong with Eclipse 3.2, it uses the
JVM on your machine (i.e. there cannot be an Eclipse
IO problem unless your JVM is messed up - which it
probably isn't). Please post some sample code.

Jessica Reuter

Posts: 2
Nickname: jezzica85
Registered: Sep, 2006

Re: Eclipse 3.2 IO Problem Posted: Sep 11, 2006 11:31 PM
Reply to this message Reply
Hi, thanks for the reply! Here's the part that doesn't seem to work, the application seems to stall and not read my files when I input them. What I'm doing is writing a document analysis utility, and I want to be able to take each chapter(each individual document) and be able to look at it in relation to the whole. You mentioned creating new files, but I don't know how much my Java app will be able to handle, overall I'll need to input almost 1 Mb of files. I'll eventually wittle them down to the important parts I need inside the application, but I need to be able to modify them inside the appllication first.
I hope this helps.
Jezzica85

public WordMiner() {
 
    	individualChapterLengths = new ArrayList<Integer>();
        uniqueWordsByChapter = new ArrayList<Integer>();
        theChapterButtons = new ArrayList<JButton>();
        allTheWords = new ArrayList<ArrayList<String>>();
 
        numberOfFiles = 0;
 
        // Set up the main frame
        minerView = new JFrame( "The Word Miner version 1.0" );
        Container pane = minerView.getContentPane();
        minerView.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
 
        mainPanel = new JPanel();
        mainPanel.setLayout( new GridLayout( 0, 1 ) );
 
        do {
            // Give option for first file input
            fileMined = JOptionPane.showInputDialog( null, 
                               "Enter READY When Input Complete", 
                               "Input File or Analyze",
                               JOptionPane.PLAIN_MESSAGE );
            System.out.println( fileMined );
 
            try {
                // If no input given but files read, prepare main window
                if( ( fileMined.equals( "" ) ) && ( numberOfFiles != 0 ) ) {
                fileMined = "READY";
                // If input is given, read in the new file
                } else if( !fileMined.equals( "READY" ) ) {
                    try {
                        readFile();	
                        JOptionPane.showMessageDialog( null, "File Read." );
                        numberOfFiles++;
                    } catch( Exception e ) {
                        e.printStackTrace();
                        System.exit( -1 );
                    }
                }
            } catch( Exception e ) {
                System.exit( -1 );
            }
        } while( !fileMined.equals( "READY" ) );
 
        if( ( fileMined.equals( "READY" ) ) && ( numberOfFiles == 0 ) ) {
            System.exit( -1 );
        }
        pane.add( mainPanel, BorderLayout.CENTER );
 
        minerView.pack();
        minerView.setVisible( true );
    }
 
    /** 
     * Reads in text files and sets up access to them
     */
 
    public void readFile() {
 
        try {
            // Create button for new file
            JButton button = new JButton( fileMined );
            button.setForeground( Color.BLACK );
            button.setBackground( Color.CYAN );
            button.addActionListener( this );
            theChapterButtons.add( button );
            mainPanel.add( button );
            
            // Read the file and skip the first line
            FileReader reader = new FileReader( fileMined );
            BufferedReader buffReader = new BufferedReader( reader );
            buffReader.readLine();
            String line = buffReader.readLine();
				
            // Set up the data lists
            ArrayList<String> chapterAll = new ArrayList<String>();
            HashSet<String> chapterUniques = new HashSet<String>();
 
            // Scan and parse the file
            String dels = "\0009\0032\0033\0040\0041\0044\0058\0059\0063" + 
                "\0133\0145\0146\0147\0148\0151";
 
            boolean numberLine = false;
            try {
                Integer.parseInt( line );
                numberLine = true;
            } catch( Exception e ) {
                numberLine = false;
            }
 
            while( line != null ) {
            	if( ( line.length() > 2 ) && ( numberLine == false ) ) {
                    StringTokenizer parser = new StringTokenizer( line, dels );
                    while( parser.hasMoreTokens() ) {
                        String temp = parser.nextToken();
                        String finalWord = temp.toLowerCase();
                        chapterUniques.add( finalWord );
                    }
                }
            }
 
            individualChapterLengths.add( chapterAll.size() );
            uniqueWordsByChapter.add( chapterUniques.size() );
            allTheWords.add( chapterAll );
 
         } catch( Exception e ) {
            System.out.println("readFile block");
            e.printStackTrace();
            System.exit(-1);
        }
    }

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Eclipse 3.2 IO Problem Posted: Sep 13, 2006 11:13 PM
Reply to this message Reply
I still don't see memory being a problem. 1MB is nothing
really. Make sure you trim fileMined, maybe there are
extra white spaces in the file name. I also don't
understand what this infinite loop is doing:

while( !fileMined.equals( "READY" ) );

while nothing is entered keep doing nothing?

Does that really need to be there?

Flat View: This topic has 3 replies on 1 page
Topic: Text floating around image in Java Previous Topic   Next Topic Topic: random access file

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use