I have program that reads user input and then writes to file. After that program reads that file and make some basic arithmetic functions. Then results are shown on screen for user.After that I want to clear that file, because it will be like cache for program, no need for permanent store.
It all works great, and I can clear file, but I got such weird exception:
java.io.UnsupportedEncodingException
And program stops.
My code: The file looks like this
2013 Jūnijs 1500.0 80 125 293.7 151.25 1055.05
2013 Jūlijs 1150.0 80 125 218.94 112.75 818.31
2013 Septembris 1550.0 80 125 304.38 156.75 1088.87
Clearing the file is done with this code :
public static void Clear_file() throws IOException{
System.out.println("Notīram failu");
clear = new Formatter(new FileWriter(user_name()+".txt", true));
FileOutputStream erasor = new FileOutputStream(user_name()+".txt");
erasor.write((new String().getBytes("")));
erasor.close();
}
I read the guide and there are written like this : If the given charset is not in that list then it is certain that this error will be thrown.
I am confused, because in the file are just String and double type data.
How can I avoid trowing this exception?
Thanks :)
erasor.write((new String().getBytes("")));to do?