下载的文件应该是.png

时间:2019-10-09 04:09:48

标签: java samba downloadfile

我不知道我的代码有什么问题,我尝试使用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();

}

连接正确,但输出数据似乎错误

the output

有什么主意吗?

1 个答案:

答案 0 :(得分:2)

那是因为您要提取构成.PNG文件的字节并打印出来,而不是将其保存为我想做的文件。

代替

PrintWriter outStream1  = resp.getWriter();

替换为此

OutputStream outStream1 = new FileOutputStream("somefile.png");

然后打开'somefile.png',您应该能够看到通过Samba下载的图像