Java 使用Apache Commons的base64字符串解码

Java 使用Apache Commons的base64字符串解码,java,base64,apache-commons,Java,Base64,Apache Commons,我正在尝试解码dropbox中的一个文件。使用此论坛中的一个帖子 import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.StringUtils; String base64String = getFileResults.get_Response();//returns a file content in base64 String result = StringUtils.new

我正在尝试解码dropbox中的一个文件。使用此论坛中的一个帖子

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
String base64String = getFileResults.get_Response();//returns a file content in base64
String result = StringUtils.newStringUtf8(Base64.decodeBase64(base64String));
但是Netbeans一直告诉我decodeBase64()不接受字符串,但是API说它接受base64中的字符串


我遗漏了什么?

请尝试
javax.xml.bind.DatatypeConverter.parseBase64Binary(base64String)
在Java SE中提供。

您遗漏了一个
。我很抱歉发布这个…我不敢相信我遗漏了那个。谢谢。不用担心,它仍然会给出相同的错误。您使用的是什么版本的apache commons?并请发布完整的错误消息。编译错误:Base64中的decode64无法应用于给定类型。必填项:byte[]found:应避免使用字符串“仅代码”答案,因为它们无法解释OP的代码(如果有)、策略或概念错误的原因,也无法解释答案正确的原因。提供解释不仅可以让OPA,也可以让所有读者了解正在发生的事情;包括对正在使用的编程语言和/或API不熟悉的人,他们可能不熟悉代码,因此可能觉得代码不直观(即使您这样做)。换句话说,记住为什么比什么更重要,特别是在答案中。
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;

...
File file = new File( "path" );
byte[] bytes = Base64.decodeBase64( "base64" );
FileUtils.writeByteArrayToFile( file, bytes );