-1

次のように文字列をデコードするコードがあります。

  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
4

1 に答える 1

1

これは、rt.jar でメソッドwriteを呼び出そうとしているためです。sun.misc.IOUtilsimport を使用する必要がありますorg.apache.commons.io.IOUtils。おそらく間違ったインポート。

于 2013-08-28T07:52:16.247 に答える