java 如何讀取遠(yuǎn)程主機(jī)文件
我就廢話不多說(shuō)了,大家還是直接看代碼吧~
package com.cloudtech.web.util; import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader; import com.cloudtech.web.entity.Role; public class RoleUtil { public static void readFile(String sourceFilePath, String encode) throws IOException {File file = new File(sourceFilePath);BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), encode));StringBuilder strBuilder = new StringBuilder();String sLine = null;while ((sLine = br.readLine()) != null) {strBuilder.append(sLine);strBuilder.append('rn');} br.close(); System.out.println(strBuilder.substring(0));}public static void main(String[] args) { try {readFile('XXXXstation_processV1010000.G1125','utf-8');} catch (IOException e) {e.printStackTrace();}}}注意:
1.其中XXXX是遠(yuǎn)程服務(wù)器的ip地址(window)
2.如果測(cè)試通過(guò),則會(huì)打印這個(gè)文件里面的數(shù)據(jù)
3.只支持window系統(tǒng),文件需要先分享后才能訪問(wèn)
補(bǔ)充:java獲取遠(yuǎn)程文件并保存到本地
解決方法:String path='https://ssl.mail.163.com/httpsEnable.gif';String file_name= contents.substring(contents.lastIndexOf('/')+1, contents.length());//獲取文件名和后綴名URL url=new URL(path);
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
相關(guān)文章:
1. PHP使用Swagger生成好看的API文檔2. Python 如何調(diào)試程序崩潰錯(cuò)誤3. Python3 json模塊之編碼解碼方法講解4. Python 利用Entrez庫(kù)篩選下載PubMed文獻(xiàn)摘要的示例5. ASP.NET MVC使用jQuery ui的progressbar實(shí)現(xiàn)進(jìn)度條6. ASP基礎(chǔ)知識(shí)VBScript基本元素講解7. Python 制作查詢商品歷史價(jià)格的小工具8. python使用jenkins發(fā)送企業(yè)微信通知的實(shí)現(xiàn)9. Python sublime安裝及配置過(guò)程詳解10. Python 合并拼接字符串的方法

網(wǎng)公網(wǎng)安備