File fileurl = new File("d:"); //判断文件路径是否存在
if(!fileurl.exists()){
fileurl.mkdirs();
}
// fileName表示你创建的文件名;为txt类型;
String filename = "答案_"+user+".txt";
//在路径上创建文件
File file = new File(fileurl, filename);
if(!file.exists()){
file.createNewFile();
}
FileOutputStream fos=null;
OutputStreamWriter osw= null;
BufferedWriter bw = null;
try {
fos = new FileOutputStream(file);
osw = new OutputStreamWriter(fos);
bw = new BufferedWriter(osw);
String s1 = new String(daan);
System.out.println(daan);
bw.write(s1);
bw.newLine();
bw.flush();
} catch (Exception e) {
e.printStackTrace();
}finally{
bw.close();
osw.close();
fos.close();
}