Results 1 to 7 of 7
  1. #1
    McChill is offline Member
    Join Date
    Feb 2009
    Posts
    47
    Rep Power
    0

    Default Compiler error invalid escape sequence

    I am getting a compiler error at this line
    Java Code:
    private static final String DICTIONARY_FILE = "C:\Users\Sterling\Documents\FlashCards.txt";
    saying "Invalid escape sequence (valid ones are \b \t \f \r \"\ ' \\).

    How can I fix this?

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Java paths always use a forward slash ("/") instead of a backslash ("\") because special characters such as the newline character begin with a backslash. Change all the backslashes in your path to forward slashes and it should work.

    Good Luck,
    Singing Boyo
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    812
    Rep Power
    6

    Default

    Hi,
    Use the String like this with escape sequence.It will work
    private static final String DICTIONARY_FILE = "C:\\Users\\Sterling\\Documents\\FlashCards.tx t";

    -Regards
    Ramya
    Ramya:cool:

  4. #4
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    441
    Rep Power
    6

    Default

    I think the way said by ramya can fix your problem.
    It is right way to avoid invalid escape sequence.
    Mak
    (Living @ Virtual World)

  5. #5
    c0rsana is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default

    I'm having the same problem with the "\",
    But if it's in quotes, shouldn't it be disregarded?

    I'm trying to create what I like to call "ASCII Art" in Java, using Eclipse as a compiler.

    The code that I'm trying to get working is:

    Java Code:
    System.out.print(" _________   ________.____                  __                 ");
    System.out.print(" \_   ___ \ /  _____/|    |    __ _________|  | __ ___________ ");
    System.out.print(" /    \  \//   \  ___|    |   |  |  \_  __ \  |/ // __ \_  __ \");
    System.out.print(" \     \___\    \_\  \    |___|  |  /|  | \/    <\  ___/|  | \/");
    System.out.print("  \______  /\______  /_______ \____/ |__|  |__|_ \\___  >__|   ");
    System.out.print("         \/        \/        \/                 \/    \/       ");
    System.out.print("     __________                   .___             __  .__                      ");
    System.out.print("     \______   \_______  ____   __| _/_ __   _____/  |_|__| ____   ____   ______");
    System.out.print("      |     ___/\_  __ \/  _ \ / __ |  |  \_/ ___\   __\  |/  _ \ /    \ /  ___/");
    System.out.print("      |    |     |  | \(  <_> ) /_/ |  |  /\  \___|  | |  (  <_> )   |  \\___ \ ");
    System.out.print("      |____|     |__|   \____/\____ |____/  \___  >__| |__|\____/|___|  /____  >");
    System.out.print("                                   \/           \/                    \/     \/ ");
    Except the lines with backslashes give me all the trouble. is there any way to bypass this problem?

    ~c0rsana

  6. #6
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default

    double your backslashes, its the onliest you can do

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    In my opinion a better solution is to put the ascii art into a text file and read it into your program. Do this and you won't need double backslashes, the text can retain its beauty and everything will still function. YMMV.

    edit: you'll also need println calls, not print.

    edit2: c0rsana: I just noticed that you hijacked an old thread. Please don't do this but instead ask a new question in a new thread. Thank you for your cooperation.
    Last edited by Fubarable; 12-01-2009 at 01:47 PM.

Similar Threads

  1. Escape Sequence
    By Punter in forum New To Java
    Replies: 4
    Last Post: 02-10-2009, 07:04 AM
  2. Escape Sequence \t does not display.
    By dreamingofgreen in forum New To Java
    Replies: 7
    Last Post: 07-22-2008, 04:50 AM
  3. Using escape sequence with like clause (%)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 09:57 AM
  4. Using escape sequence with like clause (_)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 09:55 AM
  5. Escape sequence problem
    By eva in forum New To Java
    Replies: 2
    Last Post: 01-21-2008, 10:15 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
  •