File I/O and figuring out how to get this working

I need to get this code to readi in a file from anywhere, which it does, and then calculate the sentences, words per sentence and syllables per word, this is my code so far
// Standard imports.
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
class WritingFilesWithChooser extends JFrame implements ActionListener {
     JButton myButton, myButton2;
     JTextArea myText;
     // Usual setup stuff goes in here.
     public WritingFilesWithChooser() {
          Container c = getContentPane();
          myButton = new JButton ("Write To File");
          myButton.addActionListener (this);
          myButton2 = new JButton ("Load from File");
          myButton2.addActionListener (this);
          c.add (myButton, BorderLayout.NORTH);
          myText = new JTextArea (10, 10);
          c.add (myText, BorderLayout.CENTER);
          c.add (myButton2, BorderLayout.SOUTH);
     // Usual main stuff.
     public static void main(String args[]) {
          WritingFilesWithChooser mainFrame = new WritingFilesWithChooser();
          mainFrame.setSize(400, 400);
          mainFrame.setTitle("WritingFilesWithChooser");          
          mainFrame.setVisible(true);
     // The actionPerformed for this class is a busy little beaver. It handles
     // opening and saving files, trying and catching exceptions, and dealing
     // with the chooser dialog.
     public void actionPerformed (ActionEvent e) {
     // We need these variables for our File IO.
     FileWriter base;
          PrintWriter out;
          FileReader readBase;
          BufferedReader in;
          String temp;
          JFileChooser myChooser;
          // We create an instance of JFileChooser, which allows us to use a
          // GUI style file manager to choose filenames.
          myChooser = new JFileChooser();
          // Okay, they've chosen the save button.
          if (e.getSource() == myButton) {
               // First we show the save dialog, which lets the user specifiy a
               // filename to save. If the user clicks 'save', then this if
               // condition will evaluate to true and the code within will be
               // executed. If they select cancel, then nothing will happen.
               if (myChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                    // There are often exceptions thrown when dealing with file I/O,
                    // so we need this code to deal with it.
                    try {                         
                         // We create an instance of the FileWriter object using the
                         // Chooser object. GetSelectedFile of the chooser object returns
                         // a file reference, and we call getAbsolutePath on that to get
                         // the full filename, which is returned as a string.
                         base = new FileWriter (myChooser.getSelectedFile().getAbsolutePath());
                         // We use the FileWriter object we created above as the base of
                         // the printwriter object.
                         out = new PrintWriter (base);
                         // We grab the text out of our textbox and write it to a text
                         // file.
                         out.write (myText.getText());
                         // When we're done, we close the file.
                         out.close();
                    catch (Exception except) {
                         // This will appear if there is a horrible error. More on this
                         // in week twelve.
                         JOptionPane.showMessageDialog (null, "A Horrible Error!");               
          else {
               // First we show the open dialog, which lets the user specifiy a
               // filename to open. If the user clicks 'open', then this if
               // condition will evaluate to true and the code within will be
               // executed. If they select cancel, then nothing will happen.
               if (myChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                    // There are often exceptions thrown when dealing with file I/O,
                    // so we need this code to deal with it.
                    try {
                         // We create an instance of the FileReader object using the
                         // Chooser object. GetSelectedFile of the chooser object returns
                         // a file reference, and we call getAbsolutePath on that to get
                         // the full filename, which is returned as a string.
                         readBase = new FileReader (myChooser.getSelectedFile().getAbsolutePath());
                         // We use the FileReader object we created above as the base of
                         // the BufferedReaderobject.
                         in = new BufferedReader (readBase);
                         // We read a single line from the file we selected.
                         temp = in.readLine();                         
                         temp.toLowerCase();
                         String i;
                         String word;
                         word = temp;
                         int nsyl = 0;
                         int leng = 0;
                         boolean last = true;
                         for (int j=0; j<word.length(); j ++)
                              if(word.charAt(i) = ' ')
                                   leng ++;
                         for (int k =0;k<word.length(); k++)
                              if (word.charAt(i) == 'a' || word.charAt(i) == 'e' ||
                                   word.charAt(i) == 'i' || word.charAt(i) == 'o' ||
                                   word.charAt(i) == 'u')
                                   nsyl++;
                              if (word.charAt(i) == 'a' || word.charAt(i) == 'e' ||
                                   word.charAt(i) == 'i' || word.charAt(i) == 'o' ||
                                   word.charAt(i) == 'u')
                                        last = false;
                              else {
                              last = true;
                              if (word.length(word) == "e ")
                              nsyl --;
                         // We clear the textbox, ready for us to dump our goodness into
                         // it.                         
                         myText.setText ("");
                         // This loop will continue while there are still lines to read.
                         // When the readLine method gets to the end of the file, it will
                         // assign the value 'null' to the temp variable.
                         while (temp != null) {
                              // While the temp variable isn't null, we append it to the
                              // text already in the textbox. We add the \n character to
                              // the end to force a new line.
                              myText.append (temp + "\n");
                              // We read in the next line of the file.
                              temp = in.readLine();
                         // Finally, we close the file.
                         in.close();
                    catch (Exception except) {
                         // This will appear if there is a horrible error. More on this
                         // in week twelve.
                         JOptionPane.showMessageDialog (null, "A Horrible Error!");               

How about taking a look at the String class. In jdk1.4 and later there are methods such as split() which can
split a paragraph up into sentances. (split(".") ) then can split the sentance up into words (split(" ")). Push
all of the words into a HashMap with an integer indicating the number of times they have occured.
Then run through the HashMap and for each entry search for vowels/sylables/whatever.
This is probably the easiset method of doing what you want but it is limited in the size of file it can parse
efficiently.
matfud

Similar Messages

  • Can anyone help me figure out how to get iTunes working?

    When I upgraded to iTunes 10, every time I tried to open iTunes it would give me an "Error 7: iTunes not properly installed" message. I tried uninstalling and reinstalling iTunes and restarting my computer multiple times. Finally, I went through my programs list and uninstalled all of the Apple software (QuickTime, Application Support, etc.) Then I reinstalled iTunes again.
    Now when I open iTunes, I get an "Error 2: Apple Application Support not found" message. I tried extracting the iTunesSetup.exe to a new folder and installing the AppleApplicationsSupport.msi file separately, but the installation gets partway through and gives me a "Cannot access Key (block of gibberish) Ensure you have access to key..." message and the installation fails. I'm logged into an Administrator Account, the same account that I used to install iTunes 9, so this doesn't make much sense to me.
    What can I do to get iTunes working? I really need help.

    Those are unpleasant ones, usually striking 64-bit systems. They're not easy to troubleshoot, but the following set of instructions is a good place to start:
    http://discussions.apple.com/thread.jspa?threadID=2475687&tstart=30

  • I keep getting this pop up. This web page is being redirected to a new location. Would you like to resend the form data you have typed to the new location? Can you please help me figure out how to get this to stop!

    This pop up has been occurring about once a minute when I am on certain sites.
    This web page is being redirected to a new location. Would you like to resend the form data you have typed to the new location?
    How do I get it to stop?

    -> Tap ALT key or press F10 to show the Menu Bar
    -> go to Help Menu -> select "Restart with Add-ons Disabled"
    Firefox will close then it will open up with just basic Firefox. Now do this:
    -> Update ALL your Firefox Plug-ins https://www.mozilla.com/en-US/plugincheck/
    -> go to View Menu -> Toolbars -> unselect All Unwanted toolbars
    -> go Tools Menu -> Clear Recent History ->'' Time range to clear: '''select EVERYTHING''''' -> click Details (small arrow) button -> place Checkmarks on '''Cookies & Cache''' -> click "Clear Now"
    -> go to Tools Menu -> Options -> Content -> place Checkmarks on:
    1) Block Pop-up windows 2) Load images automatically 3) Enable JavaScript
    -> go to Tools Menu -> Options -> Privacy -> History section -> Firefox will: select "Use custom settings for history" -> REMOVE Checkmark from "Permanent Private Browsing mode" -> place CHECKMARKS on:
    1) Remember my Browsing History 2) Remember Download History 3) Remember Search History 4) Accept Cookies from sites -> select "Exceptions..." button -> Click "Remove All Sites" at the bottom of "Exception - Cookies" window
    4a) Accept Third-party Cookies -> under "Keep Until" select "They Expire"
    -> go to Tools Menu -> Options -> Security -> place Checkmarks on:
    1) Warn me when sites try to install add-ons 2) Block reported attack sites 3) Block reported web forgeries 4) Remember Passwords for sites
    -> Click OK on Options window
    -> click the Favicon (small drop down menu icon) on Firefox SearchBar (its position is on the Right side of the Address Bar) -> click "Manage Search Engines" -> select all Unwanted Search Engines and click Remove -> click OK
    -> go to Tools Menu -> Add-ons -> Extensions section -> REMOVE All Unwanted/Suspicious Extensions (Add-ons) -> Restart Firefox
    You can enable your Known & Trustworthy Add-ons later. Check and tell if its working.

  • I have no "File - Edit - History - Bookmarks tool bar at the top of my screen and can't figure out how to get it!

    new desktop, new user of Windows 7. Made Firefox my browser as always, with Yahoo as my home page. There is no tool bar at the top of my screen that says "File - Edit -- History __ etc the way I have always had! I can't figure out how to get this, and I need it! Help!!

    Press the alt key next to the spacebar. Do you see it now? If so, click View -> Toolbars" and check the Menu bar. See [[Menu bar is missing]] for more information.

  • Transferring some files from old hard drive to new mac book pro: How do I do this?  I bought a SATA Wire, and can't figure out how to get my files

    Hi there, my old mac book recently died and I opted to buy a new macbook pro, instead of pouring lots of money into the old computer.  I was able to get my hard drive out, and I bought a 2.5" Sata Nootbook Drive Upgrade Kit.  I have also installed superduper!....but I can't really figure out how to get everything to work.  I just want to be able to take some of my files from my hard drive, not everything...
    Any suggestions?
    Thanks!

    I don't know what a "2.5" Sata Nootbook Drive Upgrade Kit" is but if you have a internal drive you need to connect all you needed was a $20 IDE/SATA to USB adapter
    You don't need Superduper, that's software designed to clone a entire Mac's boot drive to a external drive for bootable backup purposes using the same machine/make/model.
    Since the new Mac is different than the old one you can't clone (well you could but it will break the machine) the old drive to the new one.
    However you can use the adapter above and software Apple provides in the Utilities folder on the NEW MAC, called Migration Assistant to transfer your User to the new machine.
    However this might not be the best course of action as it can transfer unwanted data and cause problems in the Library, old programs that won't run on 10.7, etc.
    You can simply create the same named user on the machine (System Preferences > Accounts) log into it and then connect the external drive with the adapter and copy the contents of your users folders over and place into the same.
    It's always good to have another Admin level user account on the machine in case the primary one has a User based issue and you need to log into the other and grab files. So if either manually or via using Migration Assistant you wind up with two user accounts on the machine, it's really not that big of a deal.

  • I have purchased Adobe XI Pro and created a form for entering bowling scores to submit to newspaper for my high school team.  I can not figure out how to get pdf's into my documents folder on my iPad so that I can access the files in bowling alleys where

    I have purchased Adobe XI Pro and created a form for entering bowling scores to submit to newspaper for my high school team.  I can not figure out how to get pdf's into my documents folder on my iPad so that I can access the files in bowling alleys where I do not have a Wi-Fi connections.  I need to be able access files without going to acrobat.com.  Help!!!@

    Post the PDF files to a web site. The browse to them in Safari on the iPad.  When you Open the files specify the Open to occur in Adobe Reader.  Then you can have/Save them in your Documents folder on the iPad.   An iPad has limited access to files otherwise.

  • I have a FCP event and project with all accompanying media saved on a harddrive.  I am now attempting to open the files on another computer that also has FCP X.  I cannot figure out how to get it to open.

    I have a FCP event and project with all accompanying media saved on a harddrive.  I am now attempting to open the files on another computer that also has FCP X.  I cannot figure out how to get it to open.

    The events and projects folders have to be on the top level of the drive for FCP to recognize them.

  • HT4557 I have my main computer (desktop) and my laptop and my Iphone all set up under the same itunes account.  I cannot figure out how to get music that I purchased on my iphone to my desktop or laptop! I have homesharing on!  It's very frustrating!

    I have home share turned on and have a desktop for the main acct and a laptop and an I-phone.  I purchased music on my Iphone and can't figure out how to get it onto move the desktop or laptop.  It's very frustrating because I don't understand some of the I-tunes terminology and I have read through it all and did what sounds right but still no success!!  Grrrrr.....I feel like I need someone to walk me through it!

    Open itunes, connect iphone, click File>Devices>Transfer Purchases

  • I have a new iMac running iTunes 10.4 in OS 10.6.8, and a new Mac Air running iTunes 10.4 in Lion.  I was able to transfer all my music etc. from the iMac onto the Air, but cannot figure out how to get the Playlists from the iMac to the Air.  iTunes Help

    I have a new iMac running iTunes 10.4 in OS 10.6.8, and a new Mac Air running iTunes 10.4 in Lion.  I was able to transfer all my music etc. from the iMac onto the Air, but cannot figure out how to get the Playlists from the iMac to the Air.  iTunes Help says File >Library >Export playlist and choose XML, or to save a copy of all your playlists, File > Library > Export Library, "the Exported info is saved in XML format."  Then it says, "to import an iTunes playlist, File > Library > Import Playlist".  Now I am assuming I do that import part on the Air, but when I try it doesn't recognize anything that can be imported - what am I missing??? Aside from a clue...

    Thanks, Jim, for taking the time, but the reply is unfortunately vague in the exact area of my confusion!  "you need to copy that file to your new computer..."  Well, the Import/Export instructions make it seem as if the two computers should be able to communicate this file thru wifi, but that's the linkage I can't seem tocreate with Import/Export.  Should I instead email a copy to myself (thats what applecare suggested)?  Copy it to and from a thumb drive?  But then place the file where?  And the article was helpful, but should I be trying to move the Library file or the Library.xml file (as iTunes Help suggests)?  Sorry to be so clueless about it...I suppose I buy Apple in the hopes of not having to think about this stuff, which approach seems not to be serving me well. Thanks again for your time!

  • I am using iPad pages, and figuring out how to create a table of content.

    Hello
    I am using pages on my iPad Air, and figuring out how to create a table of content? (TOC)
    Anyone can help me please?

    Based on what I have found, at this time, it appears that the only way to add a TOC or Bibliography to a Pages file is via Pages for MAC. Once that is done, you can automatically add entries in Pages for iOS. But you cannot initially add the element.
    It is not out of the question that there are some templates for Pages for iOS available that already have these added and available - but I cannot say first hand. All of the built in templates for iOS appear to be for short format documents and I have yet to find one that includes the TOC or Bibliography.

  • My email screen got really large font and I cannot figure out how to get it back to normal. Has to be a Firefox thing because when I open it in Explorer it is normal size.

    While typing on my email screen (Comcast), it just started magnifying and is now quite large font. I cannot figure out how to get it back to the normal size.

    Hi,
    Please try pressing '''Ctrl''' + '''0''' (zero). This resets the zoom. Alternatively, '''View '''(Alt + '''V''') > '''Zoom''' > '''Reset'''.
    [https://support.mozilla.org/en-US/kb/how-do-i-use-zoom?s=zoom&r=0&as=s Using Zoom]
    Useful links:
    [https://support.mozilla.com/en-US/kb/Options%20window All about Tools > Options]
    [http://kb.mozillazine.org/About:config Going beyond Tools > Options - about:config]
    [http://kb.mozillazine.org/About:config_entries about:config Entries]
    [https://support.mozilla.com/en-US/kb/Page%20Info%20window Page Info] Tools (Alt + T) > Page Info, Right-click > View Page Info
    [https://support.mozilla.com/en-US/kb/Keyboard%20shortcuts Keyboard Shortcuts]
    [https://support.mozilla.com/en-US/kb/Viewing%20video%20in%20Firefox%20without%20a%20plugin Viewing Video without Plugins]
    [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder & Files]
    [https://developer.mozilla.org/en/Command_Line_Options#Browser Firefox Commands]
    [https://support.mozilla.com/en-US/kb/Basic%20Troubleshooting Basic Troubleshooting]
    [https://support.mozilla.com/en-US/kb/common-questions-after-upgrading-firefox-36 After Upgrading]
    [https://support.mozilla.com/en-US/kb/Safe%20Mode Safe Mode]
    [http://kb.mozillazine.org/Problematic_extensions Problematic Extensions]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes Troubleshooting Extensions and Themes]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20plugins Troubleshooting Plugins]
    [http://kb.mozillazine.org/Testing_plugins Testing Plugins]

  • I gifted a ringtone to my sister that I purchased from the iTunes store, and it is on her phone, but we can't figure out how to get it moved to her ringtones.  Can anyone help?

    I gifted a ringtone to my sister that I purchased from the iTunes store, and it is on her phone, but we can't figure out how to get it moved to her ringtones.  Can anyone help?

    Edit > Preferences.  Select the check box for Ringtones, this will add them to the listing in iTunes. 
    Not sure that really answers your question though.

  • I have a Verizon IPhone 4 and i can't figure out how to get my ringtones from an app to my iTunes account, it doesn't have a tab for Ringtones! I have tried unplugging it and checking if would show up but it didn't, how do you enable the ringtone folder?

    I have a verizon IPhone and i can't figure out how to get my ringtones from the app to iTunes, my account doesn't have a ringtone section in the liRingtone Folder?brary, how do you enable the ringtone folder?

    Edit > Preferences.  Select the check box for Ringtones, this will add them to the listing in iTunes. 
    Not sure that really answers your question though.

  • I purchased a book from itunes and cannot figure out how to get it on my ipod nano 7.  I cannot find an answer that works.

    I purchased an audio book from itunes and cannot figure out how to get it on my nano 7.  I have tried everything. 

    Have you double checked to make sure these Audiobooks are configured to sync to your iPod from under the iPod's Books configuration tab in iTunes?  This is assuming that the audiobooks are already stored in your iTunes library and appear under the Books category.
    To access this configuration tab, plug in your iPod and select it from under the Devices section in the left hand pane of iTunes to bring yourself to the iPod's Summary tab. Now locate the Books tab across the top in the main iTunes window and select it. Here you can configure what and how audiobooks are synced to the device.
    If you make any changes to this tab, make sure to hit the Apply button on in the lower right hand corner. This will sync the updated changes to your device.
    B-rock

  • HT6154 Can someone please just help me figure out how to update this stupid phone without losing anything? I somehow have more than one Apple ID on this,but I just want my music and my pictures to stay and I'm terrified of losing these things.

    Can someone please just help me figure out how to update this stupid phone(iPhone 4)without losing anything? I somehow have more than one Apple ID on this,but I just want my music and my pictures to stay and I'm terrified of losing these things. I have a lot of music from old CDs on here,and for some reason I can't even transfer them manually onto my computer. I'm not tech savvy whatsoever. Someone please help,having my music is the the whole reason I still have this phone.

    First read about back http://support.apple.com/kb/ht1766
    Then  read on how to transfer photos to your computer http://support.apple.com/kb/ts3195
    Then
    UPDATING iOS
    Over the air updating of iOS needs iOS 5 or later so unless you have iOS 5 or later you will not see updating in setting
    The following link explains how to update http://support.apple.com/kb/HT4972
    This link explains how to update using wireless http://support.apple.com/kb/HT4623
    This explains how to transfer purchases to your computer http://support.apple.com/kb/ht1848

Maybe you are looking for