1

First I am writing to a file and I need to read that file again but what I identify is that the file that is being written has a blank line at the end which causes problem. Although I am using replaceAll("\s","") command to avoid any spaces in string when writing to a file but it again creates space or blank lines at the end so how can I remove that to make sure that the file ends where the string end rather than having spaces at the end of the file. Here is chuck it is a bit lengthy but if it is required i'll post that too

str2= str2+","+str;
str2= str2.replaceAll("\\s","");
str2.replaceAll("(?m)^[ \t]*\r?\n", "");
File testFile1 = new File("G:/softwares/xampp/htdocs/Simulator/testFile1.csv");
File parent = testFile1.getParentFile();
if(!parent.exists() && !parent.mkdirs())
{
    throw new IllegalStateException("Couldn't create dir: " + parent);
}
FileWriter fw = new FileWriter(testFile1,false);        
PrintWriter pw = new PrintWriter(fw);
pw.println(str2);
pw.flush();
pw.close();
4

2 に答える 2