static {
try {
public static FileOutputStream fileOut = new FileOutputStream("D:/输出/" + fileName + "_main" + ".xlsx");
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
}
我这么写 提示 变量 fileOut 的修饰符不合法;只允许使用“终态"
不写trycatch又提示 未处理的异常类型 FileNotFoundException
和你try内部的无关。 FileNotFoundException 是new FileOutputStream 必须要捕获的异常。 提示你 变量 fileOut 的修饰符不合法的原因是因为你在static块中。方法内部变量是不能有访问权限修饰符的。也不允许static关键字,因为你这么方法内部创建的变量只在内部能使用。
变量前增加一个关键字:final 试试