Bidderlyn

log file java utility

Oct 24th, 2019
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package handler;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7.  
  8. public class LogWriter {
  9.  
  10. public String pathName = "//logs//log.txt";
  11. public File logFile;
  12. public PrintWriter logWriter;
  13.  
  14. public LogWriter() throws FileNotFoundException
  15. {
  16. logFile = new File(pathName);
  17. //logWriter = new PrintWriter(logFile);
  18. }
  19.  
  20. /**
  21. * will create a new log file if none by that name is created
  22. * @return success if a new log was created. Failure if not
  23. * @throws IOException
  24. */
  25. public boolean createLogFile() throws IOException
  26. {
  27. if(logFile.exists()) {
  28. logFile.delete();
  29. createLogFile();
  30. }
  31. else{
  32. logFile = new File(pathName);
  33. logFile.mkdirs();
  34. if(logFile.createNewFile()) System.out.println(">Console: New log file created"); else System.out.println(">Console: Log file already exists");
  35. return true;
  36. }
  37. return false;
  38.  
  39. }
  40.  
  41.  
  42. }
RAW Paste Data