![](/img/trans.png)
[英]How to convert HttpPostedFileBase file to Java.Io.InputStream?
[英]Write java.io.InputStream object to smb file
我的 Java 實用程序類(PGP 加密實用程序)之一讀取 java.io.File(加密格式)並將其轉換為 java.io.InputStream 對象(基本上解密文件並在方法結束)我無法修改實用程序類,因為它在整個應用程序中使用。 我需要將此對象寫入需要密碼身份驗證的共享路徑的 smb 文件。 我如何將 java.io.InputStream 轉換為 smb 文件並將其寫入共享路徑
1)是否可以使用jcifs? 2)如果可能,我們有任何示例程序嗎?
對於兩個常見的File
對象,寫過程沒有區別。
final SmbFile destFile = ... //Depends on how you init SmbFile object
InputStream inputStream = ... // your InputStream with data
OutputStream outputStream = null;
try {
outputStream = destFile.getOutputStream();
byte[] buf = new byte[STREAM_BUFFER_SIZE];
int read;
while ((read = inputStream.read(buf)) > -1) {
outputStream.write(buf, 0, read);
}
outputStream.flush();
} finally {
if (inputStream != null)
inputStream.close();
if (outputStream != null)
outputStream.close();
}
InputStream fileInputStream // already filled
File newFile = diskShare.openFile(fullFileName, EnumSet.of(AccessMask.FILE_WRITE_DATA), null, SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OVERWRITE_IF, null);
OutputStream oStream = newFile.getOutputStream();
oStream.write(fileInputStream.readAllBytes());
oStream.close();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.