Reputation: 51
I am writing some logs to a TXT file using file writer and I want to limit the size of the txt file to some value.
Once the limit is reached I want to create a new file dynamically.
Is there a way to do it in java?
Java code would be appreciated.
Upvotes: 2
Views: 2628
Reputation: 3684
Try to checking when your file exceed some lenght take an action and create new.
long SOME_VALUE = 1000;
String fileName = "test";
int i=0;
File file = new File(fileName+".txt");
public void checkAndUpdateFile(){
//do it in some loop or in some period of time
if(file.length()>SOME_VALUE){
file.close();
file = new File(fileName + String.valueOf(i++)+".txt");
}
}
Upvotes: 2