我就废话不多说了,大家还是直接看代码吧~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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( "\r\n" ); }
br.close();
System.out.println(strBuilder.substring( 0 )); }
public static void main(String[] args) { try { readFile( "\\\\XXXX\\station_process\\V1010000.G1125" , "utf-8" ); } catch (IOException e) { e.printStackTrace(); } } } |
注意:
1.其中XXXX是远程服务器的ip地址(window)
2.如果测试通过,则会打印这个文件里面的数据
3.只支持window系统,文件需要先分享后才能访问
补充:java获取远程文件并保存到本地
解决方法:
1 2 3 |
String path= "https://ssl.mail.163.com/httpsEnable.gif" ; String file_name= contents.substring(contents.lastIndexOf( "/" )+ 1 , contents.length()); //获取文件名和后缀名 URL url= new URL(path); |
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
原文链接:https://ithub.blog.csdn.net/article/details/86579716