Calendar calendar = Calendar.getInstance(); Date date = new Date(); calendar.setTime(date); int month = calendar.get(Calendar.DAY_OF_MONTH); File myFile = new File("log_"+month+".txt"); if(!myFile.exists()) { myFile.createNewFile(); PrintWriter out = new PrintWriter(myFile); out.write("Hello World"+System.lineSeparator()); out.close(); System.out.print("First Creation"); return; } if(myFile.exists()) { Path p = Paths.get(myFile.toString()); BasicFileAttributes attr = Files.readAttributes(p, BasicFileAttributes.class); FileTime creation = attr.creationTime(); DateFormat df = new SimpleDateFormat("MM:dd"); String x = df.format(creation.toMillis()); String y = new SimpleDateFormat("MM:dd").format(calendar.getTime()); attr = null; if((x).equals(y)) { FileWriter fw = new FileWriter(myFile.getAbsoluteFile(),true); BufferedWriter output = new BufferedWriter(fw); output.write("Hello World" +System.lineSeparator()); output.close(); System.out.print("Existing"); df = null; } else { myFile.delete(); myFile.createNewFile(); PrintWriter out = new PrintWriter(myFile); out.write("Hello World"+System.lineSeparator()); out.close(); System.out.print(x+y); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)