我正在开发一个基于Java SOAP的webservice应用程序,我将stdout写入文本文件作为日志供我们参考.该文件正在大量增长,因此我需要检查文件的大小...例如,如果文件大小超过10 Mb,我必须创建另一个文件.
像这样,我必须创建10个文件,一个接一个地旋转直到十个文件.达到十个文件后,我必须删除起始文件并重新开始创建...
如何在no之后删除文件.文件将变为10?
我试图将当前日期时间附加到文件名并将其传递给文件创建...所以基本上这是我的代码
public class Main {
//....
public static void main(String[] args) throws IOException
{
DateFormat dt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
String d =dt.format(date).toString();
String fname = "spy1";
File dir = new File("E:\\");
File f = new File(dir,fname+d+".txt");
if(f.createNewFile())
{
System.out.println("file creates");
}
else
{
System.out.println("file not created ");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个我的代码请帮助我如何将当前日期时间附加到文件名并使用提到的目录创建文件