我陷入了一个奇怪的情况,我必须创建一个名为 abc.dat 的 .dat 文件,但问题是当我创建它时,然后在我的 c: 驱动器中检查扩展名为 .dat 的文件不是创建的,而是扩展名为的文件类型 _auto_file 已创建,请告知我如何更正我的代码以便创建 .dat 文件扩展名...
if ( totaltsers.size()>0){
try {// Generate a file
//File file = new File(
String finalfilename= abamfilepath+ getFileName();
System.out.println(finalfilename);
File file = new File(abamfilepath+ getFileName());
FileOutputStream fileOutputStream = null;
OutputStreamWriter outputStreamWriter = null;
BufferedWriter bw = null;
Charset charset = Charset.forName("UTF-8");
CharsetEncoder charsetEncoder = charset.newEncoder();
charsetEncoder.onMalformedInput(CodingErrorAction.IGNORE);
fileOutputStream = new FileOutputStream(file.getPath());
outputStreamWriter = new OutputStreamWriter(fileOutputStream, charsetEncoder);
bw = new BufferedWriter(outputStreamWriter);
if (file.exists()){
file.delete();
}
for (tser tser : totaltsers) {
for (toabj bk : books) {
//if (tser.toabjdfr() == null)
if((tser.toabjdfr() == null) &&(tser.ghjk() == null )){
bw.write("aaa");
}
else if (tser.toabjdfr() == null && tser.ghjk() != null ){
bw.write("bb");
}
else if ( tser.toabjdfr() != null && tser.ghjk() == null){
bw.write("ccc");
}
else
bw.write("ddd");
bw.newLine();
}
}
bw.flush();
bw.close();
fileOutputStream.close();
outputStreamWriter.close();
}
catch (Exception e){
String message = "Ate exception : " + e.getMessage();
System.err.println(message);
logger.error(message);
}
}
下面是构造文件名
public String getFileName() {
return buildFileName();
}
private String buildFileName() {
String filename = "abc";
filename = filename+".dat";
return filename;
我已经按照建议进行了更改,但仍然无法正常工作..但仍然无法正常工作,请告知
String finalfilename= abamfilepath+ getFileName();
System.out.println(finalfilename);
File file = new File(abamfilepath + getFileName());
FileOutputStream fileOutputStream = new FileOutputStream(file.getPath());
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream);
BufferedWriter bw = new BufferedWriter(outputStreamWriter);
if (file.exists()) {
file.delete();
}
file.createNewFile();
}