标签: ioexception

Apache POI在读取XLSX工作簿时抛出IOException

我正在尝试运行以下代码并获得IOException:

String cellText = null;
InputStream is = null;
try {
    // Find /mydata/myworkbook.xlsx
    is = new FileInputStream("/mydata/myworkbook.xlsx");
    is.close();

    System.out.println("Found the file!");

    // Read it in as a workbook and then obtain the "widgets" sheet.
    Workbook wb = new XSSFWorkbook(is);
    Sheet sheet = wb.getSheet("widgets");

    System.out.println("Obtained the widgets sheet!");

    // Grab the 2nd row in the sheet (that contains the data we want).
    Row row = sheet.getRow(1);

    // Grab the 7th cell/col in the row (containing the Plot 500 …
Run Code Online (Sandbox Code Playgroud)

java inputstream xlsx ioexception apache-poi

0
推荐指数
1
解决办法
5145
查看次数

如何忽略异常并完成尝试

因此,我已经与这个问题作斗争了大约一周,并且认为我知道这个问题,但在确定问题之前我不想在那里报告答案。

简而言之,我在尝试使用该SerialPort.Open()命令时收到 IOException。事实证明,这是很常见的,大多数终端程序实际上也是这样做的,但它们只是忽略它。请阅读我上面的帖子以了解完整的故事。现在我想做的是忽略 IOException 但仍然打开串行端口。我不能用 try/catch 来做到这一点,或者至少我不知道如何做。

我想知道是否有一种方法可以尝试某些事情并以某种方式声明“我知道会抛出一个问题,这是一个安全的问题,我选择忽略异常并继续执行任务”。需要明确的是,我不想忽略该错误然后继续。我想忽略该错误并仍然完成操作

以下是我的最佳猜测,但它不起作用。

        try
        {
            serialPort1.Open();               
        }
        catch (System.IO.IOException)
        {
            MessageBox.Show("An IO Exception occurred.");
        }
        finally
        {          
            //SAFELY IGNORE ERROR AND DO TASK ANYWAY HERE
        }
Run Code Online (Sandbox Code Playgroud)

如果有人能帮助我解决这个问题,我将不胜感激。

编辑:如果我之后添加代码,serialport1.Open我会得到: IOException 的屏幕截图

这基本上与没有 try/catch 时发生的情况相同。我想做的是说我正在尝试这样做:我不在乎它会引发错误,无论如何都要这样做。

c# serial-port ioexception

0
推荐指数
1
解决办法
1811
查看次数

运行 powershell 命令时出错

如何使用java调用powershell命令。

  try {
        ExecuteWatchdog watchdog = new ExecuteWatchdog(20000);
        Process powerShellProcess = Runtime.getRuntime().exec(
                "powershell.exe \"D:\\testscript.ps1\"");
        if (watchdog != null) {
            watchdog.start(powerShellProcess);
        }
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(
                powerShellProcess.getInputStream()));
        String line;
        System.out.println("Output :");
        while ((line = stdInput.readLine()) != null) {
            System.out.println(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

注意:我映射了正确的路径。

我尝试使用上面的代码,但它给出了类似的错误

java.io.IOException: Cannot run program "powershell.exe": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
    at java.lang.Runtime.exec(Runtime.java:593)
    at java.lang.Runtime.exec(Runtime.java:431)
    at java.lang.Runtime.exec(Runtime.java:328)
    at com.powershell.PsJava.main(PsJava.java:17))
Run Code Online (Sandbox Code Playgroud)

任何人都可以请你帮忙。

java powershell process runtime.exec ioexception

0
推荐指数
1
解决办法
7272
查看次数

File.createNewFile()方法在Android M中抛出异常

我在Android M中创建文件时遇到问题.

我在Android 6.0.1中使用Nexus 9.然后我在我的项目中设置如下:

AndroidManifest.xml中

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud)

的build.gradle

android {
    defaultConfig {
        targetSdkVersion 23
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

MainActivity.Java

public class MainActivity extends AppCompatActivity {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
    String rootPath = storagePath + "/test";
    String fileName = "/test.zip";

    File root = new File(rootPath);
    if(!root.mkdirs()) {
        Log.i("Test", "This path is already exist: " + root.getAbsolutePath());
    }

    File file = new File(rootPath + fileName);
    try {
        if (!file.createNewFile()) {
            Log.i("Test", "This …
Run Code Online (Sandbox Code Playgroud)

java android file ioexception runtime-permissions

0
推荐指数
1
解决办法
5614
查看次数

Java.io.IO.Exception; 运行J2ME应用程序时磁盘上没有足够的空间

我得到以下错误"Java.io.IO.Exception;磁盘上没有足够的空间",而运行我的J2ME应用程序可以任何正文请告诉我这是什么类型的错误以及为什么它会来.当我将数据从移动设备上传到服务器时,会出现此错误.我不明白它在服务器端或移动端的错误在哪里.

mobile ioexception java-me

-2
推荐指数
1
解决办法
1万
查看次数

java.io.IOException:标记无效

public void createNewUser(String name, String passwort) {
        try {
            br = new BufferedReader(new FileReader("Data.txt"));
        } catch (FileNotFoundException brCreateError) {
            brCreateError.printStackTrace();
        }

        try {
            br.mark(1);
            System.out.println(br.readLine());
            try {
                if(br.readLine()==null) {
                    noUser=true;
                }else {
                    noUser=false;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            br.reset();

        } catch (IOException brMarkError) {
            brMarkError.printStackTrace();
        } ...
Run Code Online (Sandbox Code Playgroud)

为什么通过 if 语句后,markedChar 值会变为 -2?

谢谢尼科的每一个回答。

java markers reset ioexception

-4
推荐指数
1
解决办法
1万
查看次数