0

我正在尝试SmbFileInputStreamSmbFileand创建一个NtlmPasswordAuthentication。我实例化了SmbFileInputStreamtry-catch 块的外部,因此范围将不限于 try-catch 块。我对我的SmbFile,做同样的事情sf

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 loadWorkbookOrFail(String fileName){
    // create a new file input stream with the input file specified by fileName
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("MY_DOMAIN","MY_USERNAME","MY_PASSWORD");
    SmbFile sf = null;
    SmbFileInputStream fin = null;


try {sf = new SmbFile("smb:\\\\LRIFS2\\Network\\Builders\\Everymoment\\reports\\finished\\Hearthside Ph. 3.xls", auth);
    } catch (Exception e){
        System.err.println("************************************************* The try block defining sf was caught. sf is null at this time");
        throw new IllegalArgumentException("Caught exception in loadWorkbookOrFail(): " + e.getClass().getName());
    }

try{SmbFileInputStream fin = new SmbFileInputStream(sf);}
    catch(Exception e){
            System.err.println("************************************************ SmbFile sf contains " + sf);
//              System.err.println("************************************************ SmbFileInputStream fin contains " + fin);
//        System.err.println("The command we are trying to run (Drawing a NullPointerException) reads: try{" + fin + " = new SmbFileInputStream(" + sf + ")");
        throw new IllegalArgumentException("Exception caught: " + e.getClass().getName());
    }
    return loadWorkbook(fileName);
}

我收到的错误消息显示

java.lang.IllegalArgumentException: Exception caught: java.lang.NullPointerException 
at com.tem.POIStuff.loadWorkbookOrFail(POIStuff.java:723) 

我目前的理解是,通过实例化SmbFileInputStream第一个 try-catch 块的外部,它的范围将扩展到第二个块。以“我们正在尝试运行的命令”开头的错误消息的输出是

The command we are trying to run (Drawing a NullPointerException) reads: 
try{null = new SmbFileInputStream(smb:\\LRIFS2\Network\Builders\Everymoment\reports\finished\Hearthside Ph. 3.xls)

对于任何格式或连续性错误,我提前道歉。还在学习 Stack Overflow 的礼仪。

4

0 回答 0