Reputation: 23
I have created a blockchain solution and that works fine in principle but I need it so that every time the code gets executed, a new file is created in the folder. Currently it just keeps overwriting the file.
Can anyone help me out on this?
Upvotes: 1
Views: 44
Reputation: 71
Maybe you can get the current timestamp when creating the file. The timestamp is unique, so it will not have the problem of overwriting.
File f = new File("yourFileName"+System.currentTimeMillis());
Upvotes: 1
Reputation: 1615
The below code should do your work. you can keep the new Filename as unique by using transaction id as the fileName.
String dir = "Some Path";
File test = new File(dir + "newFileName");
try {
test.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
You can use the below code to get unique fileName:
public String getFileName() {
return UUID.randomUUID().toString();
}
Upvotes: 0