2016-04-13 15 views
1

JCIFSは、ローカルネットワーク上にあるテキストファイルの読み込みをAPIを使用して行います。以下のコードでファイルを開くことができます。JCIFS API Java、内部ストレージからのコピーファイル

コード:

String sharedFolder ="tratermik"; 
String path="smb://192.168.43.80/"+sharedFolder+"balanca.txt"; 
SmbFile smbFile = new SmbFile(path); 

がどのように私は私の内部メモリにこのファイルをコピーするのですか?

答えて

0

以下のコードは私の問題を解決しました。 私は誰かを助けることができるといいですか

private static final byte[] buffer = new byte[60416]; 


    public void copiar(String serverPath, String localPath) 
throws Exception { 
     SmbFile serverFile = new SmbFile("smb://192.168.43.80/tratermik/balanca.txt"); 
     File localFile  = new File("sdcard/sistemas/tratermic/balanca.txt); 

     InputStream in  = new SmbFileInputStream(serverFile); 
     OutputStream out = new FileOutputStream(localFile); 

     try { 
      while (true) { 
       synchronized (buffer) { 
        int amountRead = in.read(buffer); 
        if (amountRead == -1) { 
         break; 
        } 
        out.write(buffer, 0, amountRead); 
       } 
      } 

     } catch (Exception e) { 
      throw e; 

     } finally { 
      if (in != null) { in.close();} 
      if (out != null) {out.close();} 
     } 
    } 
} 
関連する問題