|
|
Re: Eclipse 3.2 IO Problem
|
Posted: Sep 11, 2006 11:31 PM
|
|
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);
}
}
|
|