我是一个新手用户试图弄清楚如何使用uuencode方法.我们有一个表单,只允许上传一个文本文件.现在看起来只会上传zip文件.我试图包含uuencode方法将字节转换为String,这样我们就不必修改其余的代码来容纳二进制文件.
原始代码:
public void SettingUpload(File inputfile) {
this.inputfile = inputfile;
}
Run Code Online (Sandbox Code Playgroud)
我改成了
public void SettingUpload(File inputfile){
UUEncoder uuec = new UUEncoder();
try{
InputStream is = new FileInputStream(inputfile);
OutputStream os = new FileOutputStream(inputfile);
uuec.encodeBuffer(is, os);
this.inputfile = inputfile;
}catch (Throwable error) {
reportError(error, "Error converting zipfile");
}
}
Run Code Online (Sandbox Code Playgroud)
当我测试它时,我得到了一个java.io.EOFException.我抓住了uuencoded文件并手动uudecoded它.当我试图解压缩时,
bash1:~>unzip s6b0c9e663c74f72941bd8271a5fac3b.bin
Archive: s6b0c9e663c74f72941bd8271a5fac3b.bin
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
Run Code Online (Sandbox Code Playgroud)
编辑:
我改成了:
public void SettingUpload(File inputfile){ …Run Code Online (Sandbox Code Playgroud)