Results 1 to 7 of 7
  1. #1
    Mattedatten is offline Member
    Join Date
    Aug 2009
    Location
    South Sweden
    Posts
    24
    Rep Power
    0

    Default Reading a .txt i a folder - help

    Hello all
    I'm working on a code that will open a file in a folder, depending what day it is.
    The folders are called "Mon" "Tue" etc. so the day-data from
    Calendar.getInstance().getTime().toString();
    is used.
    But if i want to open the right file ... how to? (i'm going to create a .jar file of all codes and methodes toghether when i'm done)
    Java Code:
    BufferedReader inström = new BufferedReader (new FileReader("Mon\Schema.txt"));
    Doesn't work, gives the error "illegal escape character".
    I siply want it to open and start reading from "Schema.txt" in the right day-folder.

    Any tips? ;)
    ///Mattedatten

  2. #2
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    try "/" as file separator instead.
    (and by the way there is another way: System.getProperty("file.separator") )
    have fun!
    Oh, an better do not use non-ascii charachter or see @ Create and Read Files with name including special characters (ñ, ü, é,)
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

  3. #3
    Mattedatten is offline Member
    Join Date
    Aug 2009
    Location
    South Sweden
    Posts
    24
    Rep Power
    0

    Default

    Quote Originally Posted by AndreB View Post
    try "/" as file separator instead.
    (and by the way there is another way: System.getProperty("file.separator") )
    have fun!
    Nope, it wasn't that simple :P
    At least i don't think so
    Java Code:
     unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
    should i write
    Java Code:
    throws FileNotFoundException
    in the top and hope for the best? ;P

  4. #4
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    that or you can surround it with a try/catch block
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

  5. #5
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    I think this is what you need:

    Java Code:
    BufferedReader inström = new BufferedReader (new FileReader("Mon\\Schema.txt"));
    (you need \\ instead of \)
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

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

    Default

    Quote Originally Posted by Lil_Aziz1 View Post
    (you need \\ instead of \)

    Either of the methods suggested by Andre in #2 will allow the application to work in any environment, ie won't be limited to that in which the file separator is backwards.

  7. #7
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    ooh alright, thx :)
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

Similar Threads

  1. bin and lib folder
    By sdkanhere in forum New To Java
    Replies: 1
    Last Post: 10-07-2009, 05:46 PM
  2. need to get the file name from folder
    By naveen.dpt2007 in forum New To Java
    Replies: 2
    Last Post: 09-04-2009, 07:57 PM
  3. Replies: 5
    Last Post: 08-21-2009, 12:03 PM
  4. encrypt a folder
    By subramanya2teja in forum Advanced Java
    Replies: 5
    Last Post: 03-20-2009, 01:27 AM
  5. Replies: 15
    Last Post: 03-18-2009, 11:59 PM

Posting Permissions

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