JAR을 작성하기 위해 파일에 쓰려고합니다. 그러나 NullPointerException
에 문제가 있습니다. 내 파일은 Classpath에 있습니다.NullPointerException JAR 작성 파일에 쓰는 중
(I는 JAR 파일을 생성 할 수 있기 때문에 내가 getClass()
를 사용합니다.)
어떤 이유로 내가 여기 NullPointerException
을 얻을 것? 당신의 도움을 주셔서 감사합니다. 여기
package Library;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URISyntaxException;
public class WriteJARSample {
public WriteJARSample() throws URISyntaxException, FileNotFoundException, FileNotFoundException, IOException{
write();
}
public void write() throws URISyntaxException, FileNotFoundException, IOException{
try{
File Mf=new File(getClass().getClassLoader().getResource("AllBookRecords.txt").toURI());
File Tf=new File(getClass().getClassLoader().getResource("Boutput.txt").toURI());
BufferedReader Bbr=new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("AllBookRecords.txt")));
PrintWriter Bpw=new PrintWriter(Mf);
String Bs;
while((Bs=Bbr.readLine()) != null){
Bpw.println(Bs);
}
Bpw.close();
Bbr.close();
Mf.delete();
Tf.renameTo(Mf);
}
catch(IOException ioe){
}
catch(URISyntaxException urise){
}
}
public static void main(String[] args) throws URISyntaxException, FileNotFoundException, IOException{
new WriteJARSample();
}
}
NullPointerException이 발생하는 행은 무엇입니까? – MrSmith42
"File Tf = ..."줄에서 – Sajad
getClass(). getClassLoader(). getResource ("Boutput.txt"가'null '을 반환합니다.) – MrSmith42