Results 1 to 6 of 6
  1. #1
    mickmos is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default changing writing and scanning location

    hi. im trying to make a program that takes a text file with multiple words such as;
    ---------------
    words.txt
    cat
    rat
    bat
    sat
    ---------------
    then i want to compare the first word to the second word and output the one that comes first into a temperary text file. after all the words are in the temperary text file i want to change the reading location of the scanner from the original file to the temp file and change the writing location from the temp file to the original, and repeat the process.
    can someone tell me how i change the reading and writing locations in java.
    do i have to make a new printWriter and scanner or can i just change the location of where they are looking.
    cheers.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Read the API docs.

    This is why they were written. You are looking for a method in Scanner or FileWriter that lets you change what is being scanned or the file being written.

    Java (especially these common classes) is not designed to be deliberately cryptic. If there is no method like setFile() or setSource() or whatever, you can be sure that you'll need to create a new scanner/writer.
    Last edited by pbrockway2; 04-24-2009 at 09:02 AM.

  3. #3
    mickmos is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    i have checked the api and cant seem to find anything relevant, i found the useLocale method but am unsure how to use it, it says useLocale(Locale locale)
    does this mean i would have something like;
    fileInput.useLocale(Locale "temp.txt").

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    If you looked at the API doc for Locale, you would see that it has nothing to do with file locations.

    Why use a temporary file anyway? Just keep your intermediate results in memory (an array or some kind of Collection).
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  5. #5
    mickmos is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    were not alloud to use arrarys for this assignment, and it has to be acomplished using a temp file. i have looked though the api but cant find any relevant information, im probably looking in the wrong spot. can someone just tell me the method for changing the reading and writing locations.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    OK, you've looked at the API and you "can't seem to" find anything useful. In fact - let's be bloody, bold and resolute - you didn't find anything useful. So that's it. Problem solved: you have to use new scanners and writers.

    I agree.
    Last edited by pbrockway2; 04-25-2009 at 08:54 AM. Reason: original too snarky

Similar Threads

  1. Scanning Image Pixel by Pixel
    By the_transltr in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2012, 04:01 PM
  2. scanning a file and using more than one delimiter
    By thomase in forum New To Java
    Replies: 20
    Last Post: 04-07-2009, 03:04 AM
  3. weird location of ovals
    By diggitydoggz in forum New To Java
    Replies: 6
    Last Post: 12-24-2008, 12:25 AM
  4. Java Twain Scanning
    By mwalstra in forum Advanced Java
    Replies: 3
    Last Post: 12-09-2008, 11:49 AM
  5. how to get the location of some button
    By mary in forum Java 2D
    Replies: 2
    Last Post: 08-05-2007, 04:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •