运行解码程序时的异常

时间:2013-08-28 07:36:12

标签: java

我有一个代码来解码字符串,如下所示:

  public static void main(String[] args) throws IOException {
    String base64="anybase64value"       
    byte[] bytes = Base64.decodeBase64(base64);
    String tempDir = System.getProperty("java.io.tmpdir");
    System.out.println(System.getProperty("java.io.tmpdir"));
    String testFileName = "/tmp/" + "base64.xlsx";

    FileOutputStream fos = new FileOutputStream(new File(testFileName));
    IOUtils.write(bytes, fos);
    System.out.println("Wrote " + bytes.length + " bytes to: " + testFileName);
}

但是当我运行它时会抛出一个错误:

The method write(byte[], OutputStream) in the type IOUtils is not applicable for the arguments (byte[], File)
The method close() is undefined for the type File

1 个答案:

答案 0 :(得分:1)

这是因为您尝试在rt.jar中调用write中的方法sun.misc.IOUtils。您需要使用导入org.apache.commons.io.IOUtils。可能是错误的导入。