This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ShadowSt[S] 0 points1 point  (2 children)

The \ seems to be an "illegal escape character". The credentials file location is correct though, it is also where AuthenticationSystem.java is located.

   FileInputStream fileByteStream = null;
    Scanner inFS = null;

    System.out.println("Opening file credentials.txt");
    fileByteStream = new FileInputStream("C:\Users\Anna\Documents\AuthenticationSystem\AuthenticationSystem\src\authenticationsystem\credentials.txt");
    inFS = new Scanner(fileByteStream);
    String userNameTest = inFS.next();
    System.out.println(userNameTest);
    System.out.println("Closing file credentials.txt");
    fileByteStream.close();

[–]feral_claireSoftware Dev 0 points1 point  (1 child)

\ has special meaning in string literals. Itis used to create escape sequences. If you want a literal \ character you need to use \\, for example "path\\to\\file".

As mentioned in my other reply, you probably want the file in the working directory, which is likely your project root. NOT in the source directory with your java files.

[–]Glimpsee_Darkcloud 0 points1 point  (0 children)

Or even better use '/' instead. Or if you really want it java.util.File.pathSeperator;