Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FileLog{
- private static class SplitStream extends OutputStream{
- private final OutputStream s1,s2;
- public SplitStream(OutputStream s1, OutputStream s2){
- this.s1=s1;
- this.s2=s2;
- }
- @Override
- public void write(int b) throws IOException{
- s1.write(b);
- s2.write(b);
- }
- }
- static void setUp(){
- try{
- new File("data").mkdirs();
- File logFile=new File("data/log.txt");
- FileOutputStream fileOut=new FileOutputStream(logFile);
- if(logFile.exists()) logFile.delete();
- logFile.createNewFile();
- System.setErr(new PrintStream(new SplitStream(System.err, fileOut)));
- System.setOut(new PrintStream(new SplitStream(System.out, fileOut)));
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment