直接上代码:
import java.io.*;
public class ServiceHello {
public synchronized void getValue(String fileName,byte[] content) {
// TODO Auto-generated method stub
File f = null;
OutputStream out = null;
System.out.println("文件名称:"+fileName);
String path = "E:"+f.separator+"eclipse-workspace"+f.separator+"TheService1"+f.separator+"src"+f.separator+fileName;
f = new File(path);
System.out.println("判断文件路径是否存在?");
if(f.getParentFile().exists()) {//存放fileName文件的父目录存在
try {
f.createNewFile();//则创建fileName这个文件
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {//如果存放fileName文件的父目录不存在
f.mkdirs(); //则创建整个父目录E:\eclipse-workspace\TheService1\src
try {
f.createNewFile();//并且在已创建好的父目录底下创建这个fileName文件
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
out = new FileOutputStream(f,true);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.write(content);//在此处传一个int类型的参数
}
}