Changing the way data is read into a program

Hi,
I have created a program which reads in the contents of a specified file, in this case aboutme.txt, displays the file contents on screen and counts the number of words in the file.
I would like to be able to read data from any program specified by the user when the program is executed at the linux console
e.g.
java WordCounter myfile.txt
How can i edit the code so that it will do this?
Here is the code that i have done already, which works ok
import java.io.*;
import java.util.*;
class WordCounterApp
     public static InputStreamReader input =
          new InputStreamReader(System.in);
     public static BufferedReader keyboardInput =
          new BufferedReader(input);
     public static void main(String[] args) throws IOException
          FileReader file = new FileReader("aboutme.txt");
          BufferedReader MyFile = new BufferedReader(file);
          StringTokenizer TokenizeMe;
          int NumberOfTokens = 0;
          int NumberOfWords = 0;
          TokenizeMe = new StringTokenizer(MyFile.readLine());
          NumberOfTokens = TokenizeMe.countTokens();
          while (NumberOfTokens != 0)
               for (int WordsInLine=1; WordsInLine<=NumberOfTokens;
                         WordsInLine++)
                    System.out.print(TokenizeMe.nextToken()+" ");
               System.out.println();
               NumberOfWords += NumberOfTokens;
               TokenizeMe = new StringTokenizer(MyFile.readLine());
               NumberOfTokens = TokenizeMe.countTokens();
          System.out.println("\nThere are " + NumberOfWords + " words in the file");
          MyFile.close();
thanks
Carl

Ok, heres what i have. This removes the error message but it only prints two of the three lines of text in my test file, the first and the last. so now when i run the program i get this:
java Document myfile.txt
This is my file
It is quite small, for a file
There are 11 words in the file
Whereas, it should say this:
java Document myfile.txt
This is my file
It contains several lines of text
It is quite small, for a file
There are 17 words in the file
Here is the code i now have
import java.io.*;
import java.util.*;
class Document
              public static InputStreamReader input =
                          new InputStreamReader(System.in);
              public static BufferedReader keyboardInput =
                          new BufferedReader(input);
              public static void main(String[] args) throws IOException
                          FileReader file = new FileReader(args[0]);
                          BufferedReader MyFile = new BufferedReader(file);
                          StringTokenizer TokenizeMe;
                           int NumberOfTokens = 0;
                           int NumberOfWords = 0;
               TokenizeMe = new StringTokenizer(MyFile.readLine());
               NumberOfTokens = TokenizeMe.countTokens();
               while (NumberOfTokens != 0)
                           for (int  WordsInLine=1; WordsInLine<=NumberOfTokens;
                                                                                 WordsInLine++)
                                      System.out.print(TokenizeMe.nextToken()+" ");
                          System.out.println();
                          NumberOfWords += NumberOfTokens;
                         String line = MyFile.readLine();
                         if (line==null) break;
                         TokenizeMe = new StringTokenizer(line);
                         TokenizeMe = new StringTokenizer(MyFile.readLine());
                         NumberOfTokens = TokenizeMe.countTokens();
             System.out.println("\nThere are " + NumberOfWords + " words in the file");
             MyFile.close();
}I really appreaciate the help given so far, but this is the final piece really, so a suggestion would be appreciated
thanks
Carl

Similar Messages

  • [svn:fx-4.x] 14837: Changing the way data tips are rendered in when mirrored.

    Revision: 14837
    Revision: 14837
    Author:   [email protected]
    Date:     2010-03-18 00:26:27 -0700 (Thu, 18 Mar 2010)
    Log Message:
    Changing the way data tips are rendered in when mirrored.
    Single data tip shows to left in RTL now which shows to right in LTR
    Callouts connecting datatips to chart items are also modified.
    QE notes:
    Doc notes:
    Bugs: FLEXDMV-2347 ( Datatips cluterred in bubble chart when layoutDirection=rtl)
    FLEXDMV-2348 ( Position of datatips not changing WRT layoutDirection)
    Reviewer:
    Tests run: checkintests
    Is noteworthy for integration:
    Ticket Links:
        http://bugs.adobe.com/jira/browse/FLEXDMV-2347
        http://bugs.adobe.com/jira/browse/FLEXDMV-2348
    Modified Paths:
        flex/sdk/branches/4.x/frameworks/projects/datavisualization/src/mx/charts/chartClasses/Ch artBase.as

    Setting Lightroom's preview size to larger than screen resolution is guaranteed to slow things down. I have a dual monitor system whith Lightroom showing the loupe on one screen and the grid on the other. The screen sizes are 1920x1080 and 2560x1440. Following your practice for previews would bring my system to a crawl and I have an entry level workstation.All my previews are of standard 1024x768 in size. The only delays in viewing come when Lightroom is asked to display an image where there is no preview. Once the preview has been created, browsing is near instantaneous.
    I beg to differ! The reason is that a preview can be used for any size, which is smaller than that of the preview. Scaling down a preview can be done with little or not loss in quality compared to getting the full resulution and scale that down. Scaling up is not possible.
    In your case, you will not use the previews of 1024x768 at all for full screen display. Instead you will force L3 to create bigger previews the first time you open the photo. You could try this by generating the standard previews for new imported photos before you start browsing. Then try to browse. You will probably get the "Loading" message, which indicates that the preview was not used and another one with higher resolution will be made. Then try the same experiment, setting the size of the standard preview to 2048. If, and only if, the size of your display area is not more than 2048 pixels wide and you display a photo in lanscape orientation, you will be able to browse without delay after generating the standard previews.
    If I understand your setup correctly, you display the photos in a window of 2560x1440 pixels. I suspect that only 1:1 previews could be used for that. I think Adobe should increase the maximum size of the previews to a value larger than 2048, so that you are not forced to use only the 1:1 previews.
    I agree, that when the previews have been generated, browsing is near instantaneous.

  • Is there a way to change the Digitised Date for Mov files in Lightroom?

    I am scanning some old photos.  Unfortunately Programs such as Dropbox and OneDrive display Mov files by their digitised Date.
    Consequently, My scanned photos are shown by the date that I scanned them. I can not seem to find anyway in LightRoom to change the Digitised Date so that they are shown on OneDrive/Dropbox in the correct order on my iPad.
    Any help would be appreciated.

    Your subject line says "Mov files" (which are video files), but your message talks about scanning old photos.  I'll address the old photos issue.
    Because there are so many dates/times associated with photos, and because every program feels free to use its own names, it's critical to be pedantically precise about terminology. The date/time a photo was originally taken (when the shutter was pressed) is called Date/Time Original or Capture Date. The date/time a photo was transferred to digital media is called Date/Time Digitized (when the analog file was scanned or when the digital-camera shutter was pressed). 
    A good rule of hygiene is to ensure every photo has a Date/Time Original (capture date).  Typically only digital archivists care about maintaining Date/Time Digitized.  If you ensure that every photo has a Date/Time Original, then pretty much any modern app and Web site will order your photos correctly.
    In LR, you set Date/Time Original using the Metadata > Edit Capture Time command.  By default, LR won't write the capture time back to the file's metadata, so depending on how you are transferring photos to other programs, the capture time won't necessarily get transferred.  So you either need to do Metadata > Save Metadata To File, or better, set the option Catalog Settings > Metadata > Automatically Write Changes Into XMP.
    Unfortunately, LR's Edit Capture Time isn't very flexible with dealing with scanned photos in which the precise date/time is not known.  So some people like to set an entire batch to, say, 1963/10/01 00:00:00, while others like to have each photo set in increasing increments of 1 second, so that programs will at least maintain the known relative ordering (which comes from the film or slide ordering).   To do that, you'll need a third-party plugin, e.g. ExifMeta or CaptureTime To EXIF.

  • Is it possible to change the way SAP stores a DATE field ?

    Hi,
    I have a scenario here where I have to read from a file and then upload the contents to a custom table.
    The file is comprised of several lines, each line being formatted to accomodate several fields, according to their length specifications. It's the "standard" string style to import/export files from one system to another.
    My question is: one of these fields is a date field, and I am required to order the table, afterwards, by this date field. I notice it comes as DDMMYYYY, and my SORT is not working. If I use, on the other hand, dates in YYYYMMDD format, the SORT works perfectly.
    Does SAP expects the date to come as YYYYMMDD ? Is there a way I can change this "default" format ?
    Thanks,
    Avraham

    Hi,
    Yes, SAP expects the date to come as YYYYMMDD, this is the internal format.
    I am not sure you will be able to change the default DATS format to something else.
    Other internal date format : GDATU as in table TCURF.
    Sugestion : use offsets to convert original date to internal date format and keep doing your SORT as you already did.
    Hope this will help you find de good solution.
    Issa

  • Change the way month or year page flips in Lion?

    As nits go, this is pretty nitty :-) In Lion, iCal changed the way month (and year) views changed the way they moved. Instead of just a straight transition to the next month or year, some wise guy decided to transition with a lovely (not) animation that sets off my vertigo whenever the darn page moves from month to month.
    Is there a way to revert to the previous behavior without any animation? I want a straight transition, with no flipping. I would love a classic view of iCal. I realize I am a traditionalist, a Luddite, if you will, but I dislike the colors and the current UI. I had more control over what I saw with the old iCal. I have less control now. I really dislike animation I can't control. Anyone know what I can do about that?
    Thanks, Johanna

    Those dates are read from the Capture Date filed that is in the acutal file. You can make the changes you want if you export those files to a folder on the desktop, run a 3rd party application on them and then reimport into iPhoto. Then delete the original, bad dated files.
    The application that I use to batch change the dates is PhotoInfo. It will allow you to change any one or more of the date and time values by a given amount.

  • I want to change the final date format in MM/DD/YEAR.

    HI all,
    I want to change the final date format in MM/DD/YEAR. Even my profile will be in any format like DD.MM.YY or YY.MM.DD .
    can any body tell me the way..

    declare variable:
    DATA : gv_date(10) TYPE c.
    and assign value to it:
    CONCATENATE sy-datum+4(2) sy-datum+6(2) sy-datum(4) INTO gv_date SEPARATED BY '/'

  • Changing the Target data store dynamically

    Hi,
    I have a requirement to load same kind of data into 12 different target tables. Client maintains data in period vise, i.e. Jan data in a table TABLE_01, Feb data in TABLE_02, Dec data in TABLE_12 etc. The structures of all these tables are same.
    My program will process only one period’s data at a time and processed data will be loaded into a table TABLE_SRC. After this, according to the processing period, I need to post the data into the target tables TABLE_01, TABLE_02 etc. i.e. if the data is for period Jan then to TABLE_01, data is for period Feb then to TABLE_02 and so on.
    For accomplishing the same, I need to create 12 different interfaces. So is there any way to accomplish the same using a single interface by changing the target data store dynamically? I am looking for a solution other that creating procedures.
    Any Help is appreciated.
    Thanks in advance.
    DJ

    Yes, it is possible....
    1) at the target datastore use a variable at resource
    2) create a query that returns all target tables in a source tab (procedure step)
    3) at target tab, call the interface scenario send the query result as parameter.
    That will allow you execute the same interface for disitnct targets.
    Does it help you?

  • How do I use AppleScript to Change the Creation Date to the Current Date?

    I sorted my downloads folder by creation date and found that the items were sorted seemingly randomly. On closer inspection, I saw that the creation dates were not the same as the dates that I downloaded the items, so I figures that Snow Leopard was using the date given to it by the server.
    In order to get the items sorted by download date, I figured I'd use Hazel, but it doesn't have a “change creation date” item. It does, however, have an “run AppleScript” item.
    So my question is this: how do I use AppleScript to change the creation date of an item to the current date?

    TC (Techno Cat) wrote:
    Okay, I tried changing the creation date with SetFile, but it kept giving me an error:
    What am I doing wrong?
    Looks like the date and time was not quoted
    Try this Applescript. It will change the creation date of every file in the Downloads folder to the current date and time:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #E6E6EE;
    overflow: auto;"
    title="this text can be pasted into the AppleScript Editor">
    set current_date_and_time to do shell script "date \"+%m/%d/%Y %H:%M\""
    tell application "Finder"
    set filelist to every file of the alias (the path to downloads folder as text)
    repeat with currentFile in filelist
    do shell script "/usr/bin/SetFile -d " & quoted form of current_date_and_time & space & quoted form of POSIX path of (currentFile as string)
    end repeat
    end tell</pre>

  • How we will change the lowercase data in flat file to uppercase

    How can i change the lowercase date in flat file  after uploaded, out put should be uppercase.

    Hi ramana,
    See the example.
    DO.
       READ DATASET s_filename INTO I_TEMP.
       IF SY-SUBRC <> 0.
        EXIT.
       ELSE.
         move I_TEMP to I_FINALTAB.
         append I_FINALTAB.
         clear I_FINALTAB.
      ENDIF.
    ENDDO.
         In the above code we are moving the data form file to i_temp and i_temp to I_FINAL.
    Here before moving to i_FINAL.
    use  TRANSLATE i_temp to UPPSERCASE.
    Then move to i_final.
    Pls. reward if useful.

  • Exporting or relocating masters changes the created date on the new image/file/s ?

    When I export or relocate masters onto hard drive (internal or external) it changes the created date? I have tried every option possible with no resolve. Can anyone help? eg. img98007.jpg (arranged by date in aperture and is 12/05/2001) when saved/created on the hard drive the created date will be 27/06/2008????

    I'm afraid you've lost me.
    You started off (it seemed) by asking why the image EXIF date in Aperture was different then the image file date in the Finder.
    The best I can say is that when an image is captured in a camera you get one date. When that image is made into a computer file the file will have another date.
    I want to consolidate/sync all my files over the last decade from iphoto libraries etc. The only way to do this is to import them into aperture then export them to the finder with the correct shot dates so I can sync all images.
    If it changes the created date etc. it will be impossible to do so??
    What do you mean by this? I can understand the consolidate, you want to move all your images from all sources into Aperture, not a problem, but what is the sync part referring to? And why do you feel you need to export them from Aperture once you have imported them?
    And again the created date of a file is the date the file is created it has nothing to do with the image creation date.
    Sorry I can't be of more help,
    regards

  • How could I change the Invoice date automatically in MIRO?

    Of course, I can change it manually. But the user want to calculate the due date in their own way---we have a special way to calculate the due date. So, I am looking for User-exit where I can write ABAP codes to recalculate the invoice date and cover the default invoice date, so the system can get the right due date by calculate the invoice date in the standard way.
    Did anyone have any experience in change the invoice date??Pls tell me. THKS!

    You can use the badi MRM_HEADER_DEFAULT.
    (See in transaction SE18)

  • HT3529 New 7.0 version update changes the way text messages are presented.  In the new version, I cannot figure out how to delete individual texts.  I can delete entire strings of messages, but I want to delete old texts, but keep the recent texts

    The new version of the software for my iPhone 4 changed the way text messages are managed. 
    I can no longer delete individual texts from a text "conversation."  I also have not figured out how to forward texts, which I was able to do in the prior version.
    Anyone know a way to edit out individual messages without losing the entire string?
    Anyone know if there is a way to forward messages?

    When you have the conversation open, if you tap & hold on a message bubble, you should get a new menu pop-up.  It should have 2 options "Copy" and "More..."  If you select the "More..." option it will then let you select one or more message bubbles and delete the selected ones by hitting the trach can icon in the lower left corner.  As for forwarding, you probably just select the "Copy" option, then paste the contents into a new message...

  • Urgent-change the end date for a existing wage type.

    Hi,
    Can u pls let us know how to change the end date for a existing wage type.
    The current end date is 30.8.2008  and we would like to change to 31.12.9999.
    Rgds,

    Use This report RPCLGV00
    The Wage Type Distribution report enables you to display wage types for several payroll periods. It does not take into consideration differences resulting from retroactive payroll. The report shows the current values (number and amount) for each wage type. The report evaluates the payroll records that are marked with update indicator ‘A’ when the report is run. Subsequent reporting runs may not give the same result if - in the intervening period - retroactive payroll has taken place for the evaluation period. The wage type distribution uses the data from the results table RT for the relevant payroll result. The employee’s organizational assignment is also evaluated from the payroll result. This data is taken from the Work Center Basic Pay table (WPBP).
    The wage type distribution offers you the following options for evaluation:
    Individual reporting for a specific personnel number or name.
    Totals evaluation without specifying a personnel number or name.
    You cannot use wage type distribution to run a report for several countries. You can only select payroll areas from one country for reporting.
    Scope of Function
    You use the following parameters to determine how the appearance of the wage type statement:
    Wage type for evaluation
    Enter all wage types that are to be evaluated. If you do not make an entry here, the system selects all wage types. Note that you can only select wage types that occur in the RT table.
    Evaluation start date
    Evaluation start date and evaluation end date define the evaluation period. Enter the year and payroll period for the start of the evaluation.
    Evaluation end date
    This parameter delimits the evaluation period. If you do not make an entry here, only the period from the period from the parameter Evaluation start date is evaluated.

  • Why can't I change the Created Date on a file using Terminal?

    I bought a used Contour helmet camera to take pictures of the kids while they're skiing, and I cannot access the camera itself to change the clock in it (USB port is broken).
    I get videos from it just fine, but every time I remove the battery the date/time on the camera resets to January 2008, so my skiing videos end up someplace completely different from what I expect in iMovie.
    I thought I could change the Created Date with Touch in Terminal, but it only handles the Modified Date.  I know I can purchase File Date Changer 5 from the App Store to do this, but I'd like to know why I can't do it in Terminal.
    Anybody know?  Or know of a different way that I COULD do it in Terminal?

    pessex wrote: Anybody know?  Or know of a different way that I COULD do it in Terminal?
    Don't know about Terminal, but, because you are using 10.9.x and iMovie, try the iMovie method:

  • Is it possible to change the way the time shows?

    Is it possible to change the way the time shows from 10.00 to 10:00? Why does it show with a . anyways?
    iOS 8.1.2 - iPhone 6
    Espen (Norway)

    The manual showed you the area to make changes in. As I stated earlier, it has to do with Regional formats. Just like some regions use the period between dates as well. The same is true for dates. In the US, we normally would show today's date as January 10, 2015. In many European countries, it would be 10 January 2015. The same is true for time. We generally use 12-hour format, many places use 24-hour format. How it is displayed on the phone is based on the generally accepted method for the region. If on the phone you go to Settings>General>Language & Region, you can see your regional format settings. If you go under Region Formats, tap on Advanced. That gives you the option to make some other changes if you like, rather than using the regional standards.

Maybe you are looking for