我的主目录中有以下copyfile.php文件,代码如下:
<?php
copy("dir1/test.php","dir2/test.php");
?>
基本上只是将文件从dir1移动到dir2(两个目录都已创建并存在于我的主目录中)
我使用以下java代码来调用我的copyfile.php
try {
URL url;
url = new URL( "http://www.xyz.com/copyfile.php" );
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if( conn.getResponseCode() == HttpURLConnection.HTTP_OK ){
InputStream is = conn.getInputStream();
// do something with the data here
}else{
InputStream err = conn.getErrorStream();
// err may have useful information.. but could be null see javadocs for more information
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
程序运行时没有任何错误,但文件未被复制。
但是如果我将上面的网址(http://www.xyz.com/copyfile.php)粘贴到浏览器中,则可以正常将文件复制到dir2。难道我做错了什么?请帮忙。在此先感谢:)