Code:
package Files;
import java.io.*;
public class Dateienkopieren
{
public int i;
public String pfad; // Pfad muss noch angepasst werden!
public String newfile; // Pfad muss noch angepasst werden!
public void kopieren()
{
File file = new File(newfile);
if(file.exists()) {
// tue nichts
} else {
try {
BufferedInputStream in = new BufferedInputStream(new FileInputStream(pfad));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(newfile));
while ( (i = in.read()) != -1)
out.write(i);
in.close();
out.close();
}catch (Exception e) {System.out.println( e );}
}
}
}
Code:
public void jbukopActionPerformed(final ActionEvent evt) {
pfad = (jfco1.getCurrentDirectory() + str1 + jtf1.getText() + str1 + jli1.getSelectedValue());
newfile = (jfco2.getCurrentDirectory() + str1 + jtf2.getText() + str1 + jli1.getSelectedValue());
Dateienkopieren m = new Dateienkopieren();
m.kopieren();
}
Der untere Code ist ein Auszug aus der main.
Warum bekomme ich eine Null Pointer Exception? Die Pfadangaben müssten doch stimmen! ???:L