0
我目前使用Eclipse和XAMPP做我的Android作业下载文件,我有一个代码来下载txt文件在我localhot文件夹,但它一直在说机器人不能得到
java.io.EOFException
这是我的文件夹目录,在这个目录里有1个名为电影txt文件queue.txt
C:\xampp\htdocs\android\uploads\u0001\public
这是我的网址
String url = "http://10.0.2.2/android/uploads/u0001/public/movie%20queue.txt
这是代码
URL u = new URL(url);
URLConnection conn = u.openConnection();
int contentLength = conn.getContentLength();
DataInputStream stream = new DataInputStream(u.openStream());
byte[] buffer = new byte[contentLength];
stream.readFully(buffer);
stream.close();
DataOutputStream fos = new DataOutputStream(new FileOutputStream(dest_file));
fos.write(buffer);
fos.flush();
fos.close();
错误发生在
URLConnection conn = u.openConnection();
int contentLength = conn.getContentLength();
能帮我解决吗?
你确定那个URL是正确的? - 它看起来不像。 EOF通常意味着您试图获取的文件有问题。 – sihrc
如果你有这个文件这是在你的服务器相同sd照顾 –
@sihrc因为我在我的电脑上使用XAMPP,我可以通过发送请求到http://10.0.2.2/android/login.php登录。所以我相信http://10.0.2.2是一个有效的地址 – Tiny