我用想用FileOutputStream把一个文件上传到另外的服务器上
我这样写 new FileOutputStream(上传到远程的路径);
这样写就报java.io.FileNotFoundException
不知道为什么 大家有什么号的方法 谢谢了
我这样写 new FileOutputStream(上传到远程的路径);
这样写就报java.io.FileNotFoundException
不知道为什么 大家有什么号的方法 谢谢了
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.io.*"%>
<%
//取得HttpServletRequest的InputStream输入流
InputStream is = request.getInputStream();
//以InputStream输入流为基础,建立一个BufferedReader对象
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String buffer = null;
//循环读取请求内容的每一行内容
while( (buffer = br.readLine()) != null)
{
if(buffer.endsWith("--") && buffer
.startsWith("-----------------------------"))
{
break;
}
if(buffer.startsWith("-----------------------------"))
{
if (br.readLine().indexOf("filename") > 1)
{
//跳过两行,开始处理上传的文件内容
br.readLine();
br.readLine();
//以系统时间为文件名,创建一个新文件
File file = new File(request.getRealPath("/")
+ System.currentTimeMillis());
//创建一个文件输出流
PrintStream ps = new PrintStream(new FileOutputStream(file));
String content = null;
//接着开始读取文件内容
while( (content = br.readLine()) != null)
{
if(content.startsWith("-----------------------------"))
{
break;
}
//将读到的内容输出到文件中
ps.println(content);
}
ps.flush();
ps.close();
}
}
}
br.close();
%>
这个好像是上传到本地服务器用的
远程的你试试OutputStream呢~
我也不是很清楚~
DataInputStream in = null;
DataOutputStream out = null;
try {
URL url = new File(localFile).toURL();
FileURLConnection connection = (FileURLConnection) url.openConnection();
in = new DataInputStream(connection.getInputStream());
out = new DataOutputStream(new FileOutputStream(remoteFile));
byte[] buffer = new byte[4096];
int count = 0;
while ((count = in.read(buffer)) > 0) {
out.write(buffer, 0, count);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.flush();
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
会在 out = new DataOutputStream(new FileOutputStream(remoteFile)); 这行报错
我现在想把所有的图片放到一个图片服务器上,所有现在系统中在页面里上传图片后,也要把这个图片上传到图片服务器上。
就比如 服务器1 是图片服务器,服务器2是web服务器
现在我在页面上上传了一个图片到webweb服务器上后,完成后,再从web服务器把这个文件复制到图片服务器我也知道不应该用FileOutputStream 但是不知道该用什么 大侠帮忙啊
这个我也不清楚
你去看看API呢
应该有吧~
按照我的理解,如果你做一个盘符映射,然后像这样"z:\\temp.txt"来引用的话,应该是没有问题的。
如果是这样:"\\\\192.168.1.1\\share\\temp.txt"我没有试过。
http://192.168.0.100:8080/web1/image/1.gif
你要是想做http上传的话,没有你想的这么简单的。