LapisSea

Untitled

Jan 4th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. public class FileLog{
  2.  
  3. private static class SplitStream extends OutputStream{
  4.  
  5. private final OutputStream s1,s2;
  6.  
  7. public SplitStream(OutputStream s1, OutputStream s2){
  8. this.s1=s1;
  9. this.s2=s2;
  10. }
  11.  
  12. @Override
  13. public void write(int b) throws IOException{
  14. s1.write(b);
  15. s2.write(b);
  16. }
  17. }
  18.  
  19. static void setUp(){
  20. try{
  21. new File("data").mkdirs();
  22. File logFile=new File("data/log.txt");
  23. FileOutputStream fileOut=new FileOutputStream(logFile);
  24.  
  25. if(logFile.exists()) logFile.delete();
  26. logFile.createNewFile();
  27.  
  28. System.setErr(new PrintStream(new SplitStream(System.err, fileOut)));
  29. System.setOut(new PrintStream(new SplitStream(System.out, fileOut)));
  30.  
  31. }catch(Exception e){
  32. e.printStackTrace();
  33. }
  34. }
  35. }
Add Comment
Please, Sign In to add comment