gpt4 book ai didi

Java 程序错误,提示需要类、接口(interface)或枚举

转载 作者:行者123 更新时间:2023-12-01 11:51:54 25 4
gpt4 key购买 nike

import java.io.*;

public class Test13
{
public static void main(String[] args) throws IOException

{

FileInputStream fis1 = new FileInputStream("D:/abc.txt");

FileInputStream fis2 = new FileInputStream("D:/xyz.txt");

SequenceInputStream sis = new SequenceInputStream(fis1,fis2);

int i;

while((i = sis.read())!=-1)

{

System.out.println((char)i);

}

}
}


catch(Exception ex)

{

ex.printStackTrace();

}

}

}

最佳答案

我想你尝试过类似的事情。我在异常处理中插入了一些解释

import java.io.FileInputStream;
import java.io.IOException;
import java.io.SequenceInputStream;

public class Test13 {

//because all exceptions are already catched main will never throw one
public static void main(String[] args) throws IOException {
try {
//if an exception raises anywhere from here ...

FileInputStream fis1 = new FileInputStream("D:/abc.txt");
FileInputStream fis2 = new FileInputStream("D:/xyz.txt");
SequenceInputStream sis = new SequenceInputStream(fis1, fis2);

int i;
while ((i = sis.read()) != -1) {
System.out.println((char) i);
}

//... to here ...

} catch (Exception ex) {
//this catch block code will be executed
ex.printStackTrace();
}
}

}

关于Java 程序错误,提示需要类、接口(interface)或枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28738887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com