这是我的第一篇文章,所以对于我肯定要提交的任何格式/内容虚假,我提前道歉。
我正在尝试创建一个 SmbFileInputStream 以从中创建一个 POI-HSSF 工作簿。我正在从网络驱动器中提取文件以获取一些输入。SmbFileInputStream 在 try-catch 中实例化。
package com.tem;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import jcifs.smb.*;
public static HSSFWorkbook loadWorkbook(String fileName){
// create a new file input stream with the input file specified by fileName
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("10.6.5.7","tyler","123");
try{SmbFileInputStream fin = new SmbFileInputStream("smb:" + fileName);}
catch(FileNotFoundException f){
SmbFileInputStream fin = new SmbFileInputStream("smb:" + fileName);
HSSFWorkbook wb = new HSSFWorkbook();
System.err.println("Workbook not found at ["+fileName+"], so a blank workbook has been created");
return wb;
}
// create a new org.apache.poi.poifs.filesystem.Filesystem
Path path = Paths.get(fileName);
POIFSFileSystem poifs = null;
HSSFWorkbook wb = new HSSFWorkbook();
try{poifs = new POIFSFileSystem(fin);}
catch(java.io.IOException i){throw new IllegalArgumentException("loadWorkbook could not create poifs from filename ["+fileName+"]");}
try{wb = new HSSFWorkbook(poifs);}
catch(java.io.IOException i){throw new IllegalArgumentException("loadWorkbook could not read workbook from filename ["+fileName+"]");}
try{fin.close();}
catch(java.io.IOException i){throw new IllegalArgumentException("loadWorkbook could not close workbook from filename ["+fileName+"]");}
return wb;
}
我收到的确切错误消息是
com\tem\POIStuff.java:737: error: cannot find symbol
try{poifs = new POIFSFileSystem(fin);}
^
symbol: variable fin
location: class POIStuff
com\tem\POIStuff.java:741: error: cannot find symbol
try{fin.close();}
^
symbol: variable fin
location: class POIStuff
2 errors
我正在与其他程序员一起编写此代码,因此其中一些代码略高于我的理解。但我不明白为什么 SmbFileInputStream 的实例化失败。
谢谢!