补充:该Bean用于Web应用程序中,指定目录后是否会抛出安全异常?谢谢!

解决方案 »

  1.   

    这里的路径都是以服务端的默认目录为基础:
    //建立目录路径
    private String buildDirPath(String dirName){
    String path = request.getRealPath("/");
    path += "\\dirName";
    File dirName = new File(path);
    //检查目录是否存在
    if(!dirName.exists()){
    dirName.mkdir();
    }
    return path;
    }
    //写文件
    public void writeData(String str,String path){
    try{
    FileWriter fw = new FileWriter(path + "\\" + "name.txt",true);
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(str);
    bw.newLine();
    bw.flush();
    fw.close();
    }catch(IOException e){ }
    }