您的位置:首页 > 运维架构 > Linux

Linux CentOS6系统安装最新版本Node.js环境及相关文件配置

2016-03-27 14:51 1081 查看

URL preUrl = null;
URLConnection uc = null;
try {
preUrl = new URL(http://127.0.0.1/seeyon/fileUpload+"&senderLoginName="+"zy");
uc = preUrl.openConnection();
HttpURLConnection hc = (HttpURLConnection) uc;
hc.setDoOutput(true);
hc.setUseCaches(false);
hc.setRequestProperty("contentType", "charset=utf-8");
hc.setRequestMethod("POST");
BufferedInputStream  input=new BufferedInputStream(new FileInputStream("c:/test.doc"));
String BOUNDARY = "---------------------------7d4a6d158c9"; // 分隔符
String fileName="test.doc";
StringBuffer sb = new StringBuffer();
sb.append("--");
sb.append(BOUNDARY);
sb.append("\r\n");
sb.append("Content-Disposition: form-data; \r\n name=\"1\"; filename=\""+fileName+"\"\r\n");
sb.append("Content-Type: application/msword\r\n\r\n");

hc.setRequestProperty("Content-Type",
"multipart/form-data;boundary=" + "---------------------------7d4a6d158c9");
byte[] end_data = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();
DataOutputStream dos = new DataOutputStream(hc.getOutputStream());
dos.write(sb.toString().getBytes("utf-8"));
int cc=0;
while((cc=input.read())!=-1)
{
dos.write(cc);
}
dos.write(end_data);
dos.flush();
dos.close();
FileOutputStream file=new FileOutputStream("c:/1.txt");
InputStream is = hc.getInputStream();
int ch;
while ((ch = is.read()) != -1) {
file.write(ch);
}
if (is != null)
is.close();
}
catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: