通过jcifs实现java访问网络共享文件
jcifs 是 cifs(common internet file system) java的实现
smb (service message block) to be cifs

jcifs 是一个开源项目

可从http://jcifs.samba.org/下载

SmbFileInputStream,SmbFileOutputStream,SmbFile这里对应着io里的FileInputStream
FileOutputStream,File,如果对io比较熟悉那么jcifs比较容易应用
下面一个最简单的例子说明jcifs的用法
import jcifs.smb.SmbFileInputStream;
import jcifs.smb.SmbFile;
public class ReadShareFile {

 public static void main(String[] args) {
    
  try{
   SmbFile smbFile=new SmbFile("smb://test:test@10.218.100.12/share2/aa.txt");
    //通过 smbFile.isDirectory();isFile()可以判断smbFile是文件还是文件夹
   int length=smbFile.getContentLength();//得到文件的大小
   byte buffer[] = new byte[length] ;
   SmbFileInputStream in = new SmbFileInputStream(smbFile) ;  //建立smb文件输入流
   while((in.read(buffer)) != -1){
    
    System.out.write(buffer);
    System.out.println(buffer.length);
   }
   in.close();
  }catch(Exception e){
   e.printStackTrace();
  }

 

相关文章:

  • 2021-04-20
  • 2022-01-06
  • 2021-07-22
  • 2021-11-16
  • 2022-02-27
  • 2021-12-02
  • 2021-12-19
  • 2021-06-19
猜你喜欢
  • 2021-10-23
  • 2022-12-23
  • 2021-09-07
  • 2021-07-13
  • 2021-10-20
  • 2021-08-24
相关资源
相似解决方案