我不知道我的代码有什么问题,我尝试使用sambautil从服务器下载png
if (!path.equals("")) {
SambaUtil su = new SambaUtil();
byte[] data = su.openfile(path);
log.info(path);
ByteArrayInputStream inStream = new ByteArrayInputStream(su.openfile(path));
PrintWriter outStream1 = resp.getWriter();
int bytes;
while ((bytes = inStream.read()) != -1) {
outStream1.write(bytes);
}
inStream.close();
outStream1.close();
}
连接正确,但输出数据似乎错误
有什么主意吗?
答案 0 :(得分:2)
那是因为您要提取构成.PNG文件的字节并打印出来,而不是将其保存为我想做的文件。
代替
PrintWriter outStream1 = resp.getWriter();
替换为此
OutputStream outStream1 = new FileOutputStream("somefile.png");
然后打开'somefile.png',您应该能够看到通过Samba下载的图像