ファイルに書き込んで JAR を作成しようとしています。しかし、私は問題を抱えていNullPointerException
ます。私のファイルはクラスパスにあります。
( getClass()
JARファイルを作成するので使用します。)
ここに来る理由はあり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();
}
}