I have a Java program that prompts user for input file path and name, the program will read from that file:
Scanner inScanner = new Scanner(System.in);
inScanner.useDelimiter("\n");
System.out.print("Enter input file path and name:");
String inFile = inScanner.next();
System.out.println("You entered: " + inFile);
FileInputStream fs = new FileInputStream(inFile); // FAILED HERE
When I ran this program within Eclipse, I got the "syntax is incorrect" error:
Enter input file path and name: C:\\Users\\My Work\\myFile.txt
You entered: C:\\Users\\My Work\\myFile.txt
(The filename, directory name, or volume label syntax is incorrect)rks\myFile.txt
But it worked fine if I gave the same path hardcoded in the same java program and created FileInputStream from this hardcode value:
private static final String inFile = "C:\\Users\\My Work\\myFile.txt";
So how do I give this path from input in Eclipse? Is it because I have space in the path? I have tried using double quotes around the input file path, or single \, or single / in the file path, it gave me the same error. Thanks.