HOWTO · Java
시스템이 Java에 지정된 파일을 찾을 수 없음
이 자습서는 Java에서 오류를 해결하는 방법을 보여줍니다. 시스템이 지정된 파일을 찾을 수 없습니다.
이 자습서는 Java에서 시스템이 지정된 파일을 찾을 수 없습니다 오류를 해결하는 방법을 보여줍니다.
Java에서 시스템이 지정된 파일을 찾을 수 없습니다 오류 수정
Java 오류 시스템이 지정된 파일을 찾을 수 없습니다는 로드 중인 파일이 디렉토리에 없거나 파일 이름이 올바르지 않을 때 발생합니다. 또한 시스템이 주어진 이름을 가진 파일을 찾을 수 없을 때 발생하는 Java IO 패키지의 예외입니다.
이와 동일한 오류가 발생하는 예를 살펴보겠습니다.
package delftstack;
import java.io.*;
public class Example {
public static void main(String[] args) {
try {
File NewFile = new File("NewDelftstack.txt");
System.out.println(NewFile.getCanonicalPath());
FileInputStream File_Input_Stream = new FileInputStream(NewFile);
DataInputStream Data_Input_Stream = new DataInputStream(File_Input_Stream);
BufferedReader Buffered_Reader = new BufferedReader(new InputStreamReader(Data_Input_Stream));
String line;
while ((line = Buffered_Reader.readLine()) != null) {
System.out.println(line);
}
Data_Input_Stream.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
NewDelftstack.txt 파일이 디렉토리에 없으므로 위의 코드는 오류를 발생시킵니다. 출력 참조:
C:\Users\Sheeraz\eclipse-workspace\Demos\NewDelftstack.txt
Error: NewDelftstack.txt (The system cannot find the file specified)
이 문제를 해결하려면 올바른 파일 이름과 경로를 입력했는지 확인하십시오. 올바른 이름과 경로를 입력한 경우 도움이 되는 Java의 파일 목록을 확인할 수도 있습니다.
예를 참조하십시오:
package delftstack;
import java.io.*;
public class Example {
public static void main(String[] args) {
try {
File file = new File(".");
for (String fileNames : file.list()) System.out.println(fileNames);
File NewFile = new File("NewDelftstack.txt");
System.out.println(NewFile.getCanonicalPath());
FileInputStream File_Input_Stream = new FileInputStream(NewFile);
DataInputStream Data_Input_Stream = new DataInputStream(File_Input_Stream);
BufferedReader Buffered_Reader = new BufferedReader(new InputStreamReader(Data_Input_Stream));
String line;
while ((line = Buffered_Reader.readLine()) != null) {
System.out.println(line);
}
Data_Input_Stream.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
위의 코드는 디렉토리에 있는 파일 목록을 표시하며 파일을 찾은 다음 코드에서 파일 이름과 경로를 수정할 수 있습니다. 출력 참조:
.classpath
.project
bin
Delftstack.png
delftstack.txt
delftstack.xml
delftstack.zip
src
C:\Users\Sheeraz\eclipse-workspace\Demos\NewDelftstack.txt
Error: NewDelftstack.txt (The system cannot find the file specified)
디렉토리에 NewDelftstack.txt 파일이 없습니다. 이 이름으로 파일을 만들거나 코드에서 파일 이름을 변경할 수 있습니다.
예를 참조하십시오:
package delftstack;
import java.io.*;
public class Example {
public static void main(String[] args) {
try {
File NewFile = new File("Delftstack.txt");
System.out.println(NewFile.getCanonicalPath());
FileInputStream File_Input_Stream = new FileInputStream(NewFile);
DataInputStream Data_Input_Stream = new DataInputStream(File_Input_Stream);
BufferedReader Buffered_Reader = new BufferedReader(new InputStreamReader(Data_Input_Stream));
String line;
while ((line = Buffered_Reader.readLine()) != null) {
System.out.println(line);
}
Data_Input_Stream.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
디렉토리에 Delftstack.txt 파일이 포함되어 있으므로 코드가 제대로 작동합니다. 출력 참조:
C:\Users\Sheeraz\eclipse-workspace\Demos\delftstack.txt
Hello, This is a new text file from delftstack.com after overwriting the previous file.