J
JJay-JJay
Gast
Guten Tag.
Ich finde das Problem nicht. Wäre lieb, wenn sich das jemand mal anschauen könnte. Ich bin noch Anfänger.
Das ist der Programmteil, um den es geht:
und das die dazugehörige Fehlermeldung:
Er kommt also bis zum FileOutputStream. Aber ich weiß nicht, warum es da nicht weitergeht. Kann mir jemand das Problem benennen? ^^
Vielen lieben Dank im Voraus.
Gruß
JJay-JJay
Ich finde das Problem nicht. Wäre lieb, wenn sich das jemand mal anschauen könnte. Ich bin noch Anfänger.
Das ist der Programmteil, um den es geht:
Java:
void pb_einlesen_for_MouseClicked() {
btEinlesen.addActionListener(this);
setTitle("Einlesen und Verarbeiten");
setSize(650, 440);
setVisible(true);
// ein shortcut zum Schließen
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e) {
fd1.setVisible(true);
lab1.setText("Directory: " + fd1.getDirectory());
display(fd1.getDirectory() + fd1.getFile());
}
public void display(String fname) { // Pfad auslesen
try {
FileInputStream fis1 = new FileInputStream(fname);
int fileSize = fis1.available();
byte buf1[] = new byte[fileSize];
fis1.read(buf1);
String str1 = new String(buf1);
ta1.setText(str1);
} catch (IOException e) {
System.exit(0);
}
System.out.println("fname " + fname);
fpath = fname;
System.out.println("fpath " + fpath);
try {
Process p = Runtime.getRuntime().exec(
"rundll32 url.dll,FileProtocolHandler " + fname);
} catch (Exception err) {
err.printStackTrace();
}
}
// Formatieren und Rechnen
void pb_verarbeiten_for_MouseClicked() {
HSSFWorkbook wb = null;
FileInputStream input = null;
try {
input = new FileInputStream(fpath);
System.out.println("Pfad angekommen.");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("fpath " + fpath);
System.out.println("Pfad nicht gefunden.");
Fehler fail = new Fehler();
e.printStackTrace();
}
try {
wb = new org.apache.poi.hssf.usermodel.HSSFWorkbook(input);
System.out.println("Es funktioniert.");
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Pfad konnte nicht erfolgreich übernommen werden.");
e.printStackTrace();
}
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(2);
HSSFCell cell = row.getCell((short) 3);
if (cell == null)
cell = row.createCell((short) 3);
cell.setCellValue("a test");
System.out.println("In die Zelle geschrieben.");
// Write the output to a file
FileOutputStream fileOut = null;
try {
fileOut = new FileOutputStream(fpath);
} catch (FileNotFoundException e) {
System.out.println("Fehler beim Erstellen des FileOutputStreams.");
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
wb.write(fileOut);
} catch (IOException e) {
System.out.println("Fehler beim Schreiben in den FileOutputStream.");
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fileOut.close();
} catch (IOException e) {
System.out.println("Fehler beim Schließen des FileOutputStreams.");
// TODO Auto-generated catch block
e.printStackTrace();
}
und das die dazugehörige Fehlermeldung:
Java:
fname C:\test\TestdateiNotizen.xls
fpath C:\test\TestdateiNotizen.xls
Pfad angekommen.
Es funktioniert.
In die Zelle geschrieben.
Fehler beim Erstellen des FileOutputStreams.
java.io.FileNotFoundException: C:\test\TestdateiNotizen.xls (The requested operation cannot be performed on a file with a user-mapped section open)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at HauptfensterEditor.pb_verarbeiten_for_MouseClicked(HauptfensterEditor.java:335)
at HauptfensterEditor$MyMouseAdapter.mouseClicked(HauptfensterEditor.java:228)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.apache.poi.poifs.storage.BigBlock.doWriteData(BigBlock.java:55)
at org.apache.poi.poifs.storage.HeaderBlockWriter.writeData(HeaderBlockWriter.java:214)
at org.apache.poi.poifs.storage.BigBlock.writeBlocks(BigBlock.java:86)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.writeFilesystem(POIFSFileSystem.java:263)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:916)
at HauptfensterEditor.pb_verarbeiten_for_MouseClicked(HauptfensterEditor.java:342)
at HauptfensterEditor$MyMouseAdapter.mouseClicked(HauptfensterEditor.java:228)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
Er kommt also bis zum FileOutputStream. Aber ich weiß nicht, warum es da nicht weitergeht. Kann mir jemand das Problem benennen? ^^
Vielen lieben Dank im Voraus.
Gruß
JJay-JJay