java - how to clear file before putting data there? -
i need save data text file. i'm using class files
method write()
. if such file doesn't exist - alright. problem if such file exists appends new data end of file. , need clear first. code is:
public static void main(string[] args) { depolist test0 = new depolist(); test0.init(); arraylist<depo> list0 = test0.getlist(); collections.sort(list0); (depo depo : list0) { string str = string.format("sum = %1$8.2f interest = %2$7.2f\n", depo.getsum(), depo.getincome()); system.out.format(str); try { files.write(paths.get("depo.txt"), str.getbytes(), standardopenoption.create, standardopenoption.append); } catch (ioexception e) { e.printstacktrace(); } } system.out.println();
i think need add standardopenoperation
. how clear file before putting data there?
remove standardopenoption.create,standardoption.append
appends new data existing one
use files.write((paths.get("depo.txt"), str.getbytes());
Comments
Post a Comment