java訪問區域網路共用資源

來源:互聯網
上載者:User

標籤:java 共用檔案 區域網路

       本地要讀取存在另一台電腦上的檔案,兩台主機在同一區域網路中,互相拷貝費時費力。只需將要訪問的資源設定成資源共用,就可以在區域網路其他主機讀取該檔案。

       首先,將要訪問檔案所在檔案夾設定為“共用資料夾”。

       接下來就可以訪問了:

public class Testtelnet {public static void main(String[] args) {// TODO Auto-generated method stub        File file = new File("\\\\ROYAL-PC\\thinkinjava");        File[] lists = file.listFiles();        for(File file1:lists){        System.out.println(file1.getName());        }}}

結果:

javaio.docx
java常用.docx
java並發.docx
synchronized vs lock.docx
think in java.docx
threadpool.docx
~$ink in java.docx
類載入器.docx
設計模式.docx
讀取設定檔.docx
進程與線程.docx


檔案路徑為“\\\\ROYAL-PC\\thinkinjava”,ROYAL-PC為對方主機名稱,利用IP地址也可以訪問。地址分隔字元前需要用轉義符“\”。

       



java訪問區域網路共用資源

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.