javasmb上傳文件
『壹』 java讀取linux系統中文文件名時候亂碼,並顯示文件不存在
同學,這個很麻煩的,大哥解決方案就是存文件加碼,取文件解碼。用base64這個東西,你可以網路一下。然後在linux下就不存在有中文文件了。
『貳』 java上傳圖片到遠程伺服器上,怎麼解決呢
需要這樣的一個包 jcifs-1.1.11
public static void forcdt(String dir){
InputStream in = null;
OutputStream out = null;
File localFile = new File(dir);
try{
//創建file類 傳入本地文件路徑
//獲得本地文件的名字
String fileName = localFile.getName();
//將本地文件的名字和遠程目錄的名字拼接在一起
//確保上傳後的文件於本地文件名字相同
SmbFile remoteFile = new SmbFile("smb://administrator:[email protected]/e$/aa/");
//創建讀取緩沖流把本地的文件與程序連接在一起
in = new BufferedInputStream(new FileInputStream(localFile));
//創建一個寫出緩沖流(注意jcifs-1.3.15.jar包 類名為Smb開頭的類為控制遠程共享計算機"io"包)
//將遠程的文件路徑傳入SmbFileOutputStream中 並用 緩沖流套接
out = new BufferedOutputStream(new SmbFileOutputStream(remoteFile+"/"+fileName));
//創建中轉位元組數組
byte[] buffer = new byte[1024];
while(in.read(buffer)!=-1){//in對象的read方法返回-1為 文件以讀取完畢
out.write(buffer);
buffer = new byte[1024];
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
//注意用完操作io對象的方法後關閉這些資源,走則 造成文件上傳失敗等問題。!
out.close();
in.close();
}catch(Exception e){
e.printStackTrace();}
}
}
『叄』 java如何訪問區域網共享文件
java訪問共享文件夾,讀取區域網中一台機器的共享目錄中的文件,需要jcifs-1.1.11.jar的支持,使用SMB協議,以下是實現了遠程讀取文件的功能代碼:
packagejunit;
importjcifs.smb.SmbFile;
/**
*java訪問區域網共享目錄
*
*@authoradministrator
*@version1.02015-7-6
*/
publicclassSmbTest{
publicstaticvoidmain(String[]args)throwsException{
//smb://xxx:[email protected]/testIndex/
//xxx:xxx是共享機器的用戶名密碼
Stringurl="smb://192.168.2.188/testIndex/";
SmbFilefile=newSmbFile(url);
if(file.exists()){
SmbFile[]files=file.listFiles();
for(SmbFilef:files){
System.out.println(f.getName());
}
}
}
}