81,092
社区成员
发帖
与我相关
我的任务
分享
try {
// 将文件转化为文件输入流
FileInputStream input = new FileInputStream("c:\\abc.doc");
int total = 0;
// 将byte[]类型转化,放入StringBuffer中.
while ((total = input.read(bt)) != -1) {
for (int i = 0; i < total; i++) {
sb.append((char) bt[i]);
}
}
// 关闭文件输入流
input.close();
addDoc(sb.toString(),"abc.doc");
} catch (IOException e) {
}
/**
* 测试接受文件
* @param docStr
* @param name
* @return
*/
private Boolean addDoc(String docStr,String name) {
File dirFile;
// 判断是否存在文件夹
boolean bFile = false;
// 返回值
boolean rtnValue = false;
try {
dirFile = new File("e:\\" + "2");
bFile = dirFile.exists();
if (bFile != true) {
bFile = dirFile.mkdir();
System.out.println("Create successfully!");
}
OutputStream out = new FileOutputStream("e:\\" + "2" + "\\"
+ name);
DataOutputStream dos = new DataOutputStream(out);
dos.write(docStr.getBytes());
out.close();
dos.close();
rtnValue = true;
} catch (IOException e) {
rtnValue = false;
}
return rtnValue;
}