发布网友 发布时间:2022-05-14 10:16
共3个回答
热心网友 时间:2023-09-18 00:09
就是如果存在的话返回“true”,否则就是返回“false”。举例:热心网友 时间:2023-09-18 00:10
file 只能操作本地文件追答import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import ch.unifr.article.util.Constant;
public class ReadInformation {
/**
* @param args
*/
private InputStream l_urlStream;
private FileWriter fw;
private String coding = "UTF-8";
public String getUrlText(String s) {
String text = "";
String sCurrentLine = "";
try {
URL url = new URL(s);
java.net.HttpURLConnection l_connection = (java.net.HttpURLConnection) url
.openConnection();
l_connection.connect();
l_urlStream = l_connection.getInputStream();
java.io.InputStreamReader read = new InputStreamReader(l_urlStream,
coding);
java.io.BufferedReader l_reader = new java.io.BufferedReader(read);
while ((sCurrentLine = l_reader.readLine()) != null) {
text += sCurrentLine;
}// viewSource(url);
} catch (MalformedURLException ex) {
System.out.println("网络连接错误:" + s);
ex.printStackTrace();
} catch (FileNotFoundException e) {
System.out.println("文件不存在:" + s);
e.printStackTrace();
} catch (IOException e) {
System.out.println("其他IO错误:" + s);
e.printStackTrace();
}
return text;
}
public static void main(String[] args) {
ReadInformation ri = new ReadInformation();
String url = "http://xxxx.com/sss.txt";//此处请lz填写txt地址
System.out.println(ri.getUrlText(url));
}
}
热心网友 时间:2023-09-18 00:10
这个貌似file类不行,