따옴표 붙은 파일 이름이나 인용되지 않은 파일 이름을 입력하려고했지만 여전히 첫 번째 공간까지만 처리합니다. 경로에 공백이 없더라도 파일은 감지되지 않지만 경로는 올바르게 표시됩니다. 그것을 고치는 방법?"파일 이름, 디렉터리 이름 또는 볼륨 레이블 구문이 올바르지 않습니다."
Enter the filename: a b c
java.io.FileNotFoundException: a (The system cannot find the file specified)
Enter the filename: "a b c "
java.io.FileNotFoundException: "a (The system cannot find the file specified)
파일 입력을 얻는 가장 좋은 방법입니까? 또한 IOException, FileNotFoundException을 main에 추가하거나 try {}를 사용하여 추가해야합니까?
System.out.print("Enter the filename: ");
Scanner stdin = new Scanner((System.in)); //Keyboard input
String nextDataValue, data, popped="", tag="", fileName=stdin.next();
FileInputStream fis = null;
try {
fis = new FileInputStream(fileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
InputStreamReader inStream = new InputStreamReader(fis);
BufferedReader in = new BufferedReader(inStream);
data=in.readLine();
공백이있는 파일 이름을 읽으려고합니까? –
경로에 공백이 있습니다. – user93200
'next()'대신'nextLine()'을 사용하거나 @ MДΓΓLLLLLL의 제안과 함께하십시오. – chrisn