/**
*
* @Title: redFileByURL
* @Description: 通过URL读取文件
* @param path URL地址
* @param method 提交方式 post/get
* @param encoding 编码方式
* @param @throws Exception
* @return String res 返回读取到的文件
* @throws
*/
public static String readFileByURL(String path,String method,String encode)throws Exception{
String res = "";
URL url = new URL(path);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod(method);
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(),encode));
String line;
while ((line = in.readLine()) != null) {
res += line;
}
String temp = res;
in.close();
return temp;
}
通过URL读取文件
最新推荐文章于 2024-05-16 10:23:10 发布