この次のscippetはうまく機能し、私は多くのプロジェクトでそれを使用しています。ただし、この1つのプロジェクトでは、ファイルが見つからないという例外が発生します。
try {
FileInputStream is = new FileInputStream(file);
String original = file.getName();
Logger.debug("Filename in upload pf %s ", original);
IOUtils.copy(is, new FileOutputStream(Play.getFile(original)));
PfParser p1 = new PfParser();
p1.read(original, month, year);
Payroll.index();
} catch (FileNotFoundException e) {
Logger.error(e, "Exception in uploadSheet: ");
e.printStackTrace();
} catch (IOException e) {
Logger.error(e, "Exception in uploadSheet: ");
e.printStackTrace();
}
これはreadメソッドであり、コメントアウトされているいくつかの組み合わせを試しました。
FileInputStream myInput = new FileInputStream(
System.getProperty("user.dir") + inputFile);
w = Workbook.getWorkbook(myInput);
// w = Workbook.getWorkbook(new File(inputFile));
// w = Workbook.getWorkbook(new File(System.getProperty("user.dir"),
// inputFile));
C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\application
これにより、ファイルがフォルダーにアップロードされます。
Jexcelを使用してExcelファイルを読み取ろうとしています。サーバーで発生するエラー:
java.io.FileNotFoundException: foo.xls (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
他の(コメントアウトされた)行を試してみると、エラーのバリエーションのみが得られます。
java.io.FileNotFoundException: C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0\foo.xls (The system cannot find the file specified)
絶対パスと相対パスに関連する問題は理解していますが、解決策が見つからないようです。Ubuntuであるローカルマシンでコーディングおよびテストしている間、エラーは発生しません。Windowsサーバーに展開した場合にのみ、これらの問題が発生します。
ありがとう。