Friday, 9 August 2013

file creation process get corrupted

file creation process get corrupted

I am stuck up in a odd situation I have to create a .dat file named
abc.dat but the issue is that when I create it then in my c: drive I check
that file with extension .dat is not created instead file with extension
type _auto_file is created , please advise how can I correct my code so
that .dat file extension get created...
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);
}
}
below are the to construct the file name
public String getFileName() {
return buildFileName();
}
private String buildFileName() {
String filename = "abc";
filename = filename+".dat";
return filename;
i have done the changes as suggested but still not working.. but it is
still not working please advise
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();
}
the issue is still same dat file is not get created instead the file of
type _auto_file gt created of size 0

No comments:

Post a Comment