我是一个新手用户,试图弄清楚如何使用 uuencode 方法。我们有一个只允许上传单个文本文件的表单。现在看起来只会上传 zip 文件。我正在尝试包含 uuencode 方法来将字节转换为字符串,这样我们就不必修改其余代码来适应二进制文件。
原始代码:
public void SettingUpload(File inputfile) {
this.inputfile = inputfile;
}
我把它改成
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");
}
}
当我测试它时,我得到了一个 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
编辑:
我将其更改为:
public void SettingUpload(File inputfile){
UUEncoder uuec = new UUEncoder();
try{
InputStream is = new FileInputStream(inputfile);
File OutputFile=new File("Output");
OutputFile.createNewFile();
OutputStream os = new FileOutputStream(OutputFile);
uuec.encodeBuffer(is, os);
this.OutputFile = OutputFile;
}catch (Throwable error) {
reportError(error, "Error converting zipfile");
}
}
我收到以下错误:
cannot find symbol
symbol : variable OutputFile