try {//创建一个URL实例URL url = new URL("http:XXXXXXXXXXXXXXXXXXX");InputStream is=url.openStream();InputStreamReader isr = new InputStreamReader(is, "utf-8");byte[] bytes=new byte[20];String str=new String(bytes,"utf-8");BufferedReader br = new BufferedReader(isr);String data = br.readLine();//读取数据while (data != null) {//循环读取数据System.out.println(data);//输出数据data = br.readLine();}br.close();isr.close();is.close();videoTitles1[0] = "Y";}catch(IOException e){videoTitles1[0] = "错误";}
1 回答
牧羊人nacy
TA贡献1862条经验 获得超7个赞
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
/**
* @author lmq
*
*/
public class RemoteFile {
public static void main(String[] args) throws Exception {
File remoteFile = new File("//192.168.7.146/test/1.txt");// 192.168.7.146是对方机器IP,test是对方那个共享文件夹名字,如果没有共享是访问不到的
//远程文件其实主要是地址,地址弄对了就和本地文件没什么区别 ,windows里面//或者\\\\开头就表示这个文件是网络路径了其实这个地址就像我们再windows里面,点击开始
//然后点击运行,然后输入 \\192.168.7.146/test/1.txt访问远程文件一样的
BufferedReader br = new BufferedReader(new FileReader(remoteFile));
String str;
while ((str = br.readLine()) != null) {
System.out.println(str);
}
br.close();
}
}
添加回答
举报
0/150
提交
取消