zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package Method;
import java.io.*;
 
import Frame.TcpIpManage;
 
/**ʵʱ±£´æ±¨ÎÄÊý¾Ý*/
public class SaveFIleInTxt {    
    static File file=new File("./savefile/ת·¢±¨ÎÄ.txt");
    static File file1=new File("./savefile/±¨ÎÄ.txt");    
    static File file3=new File("./savefile/beifen.txt");
    static File file5=new File("./savefile/log.txt");
    static File filedisplay=new File("./savefile/±¨ÎÄdisplay.txt");
    static File filegngga=new File("./savefile/±¨ÎÄgngga.txt");    
 
    public static void insert_intxt(String message)  {
        save_in_txt(message,file,true);
    }
 
    /**±£´ædisplay±¨ÎÄ**/
    public static void save_display(String message,String tagid)  {
        boolean showtagid=TcpIpManage.getNeed_guo_lv_tag().equals(tagid);
        boolean alltagid=TcpIpManage.getNeed_guo_lv_tag().equals("Ñ¡Ôñ±êÇ©");    
        if(showtagid || alltagid ) {
            save_in_txt(message,filedisplay,true);            
        }
    }
 
    /**±£´ægngga±¨Îı¨ÎÄ**/
    public static void save_gngga(String message,String tagid)  {
        String aaa=GetNowTime.now2()+","+message;
        boolean showtagid=TcpIpManage.getNeed_guo_lv_tag().equals(tagid);
        boolean alltagid=TcpIpManage.getNeed_guo_lv_tag().equals("Ñ¡Ôñ±êÇ©");    
        if(showtagid || alltagid ) {
            save_in_txt(aaa,filegngga,true);
        }
    }
 
 
    /**±£´æÊý¾Ý½øÈ뱨ÎÄtxt*/
    public static void save_baowen(String message)  {                
        save_in_txt(message,file1,true);
    }
 
    /**±£´æÊý¾Ý½øÈ뱨ÎÄtxt*/
    public static void save_jiexibaowen(String message,File fileName)  {
        save_in_txt(message,fileName,true);
    }
 
    /**Êý¾Ý±¸·Ý*/
    public static void bei_fen(String message)  {
        save_in_txt(message,file3,false);        
    }
 
 
 
    public static File creatFile(){
        String getyearmd = GetNowTime.getyearmd();
        File file=new File("./savefile/"+getyearmd+".log");
        if (file.exists()){
            return file;
        }else {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return file;
    }
 
 
    public static File creatFilelog(){
        File file = new File("./run0c.txt");
        try {
            if (file.exists()) {
                FileWriter fileWriter = new FileWriter(file);
                fileWriter.write("");
                fileWriter.flush();
                fileWriter.close();
                return file;
            } else {
                file.createNewFile();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return file;
    }
 
 
    /**Êý¾Ý´æÔÚ²Ù×÷ÈÕÖ¾*/
    public static void savelog(String message)  {
        save_in_txt(message,file5,true);        
    }
 
    /**±£´æÊý¾Ý½øÈëtxtÎĵµ
     * @param String messageÐèÒª±£´æµÄÄÚÈÝ
     * @param File Îļþ±£´æÂ·¾¶
     * @param boolean fugaiÄÚÈÝÊǸ²¸Ç»¹ÊÇ×·¼Ó*/
    public static void save_in_txt(String message,File file,boolean fugai)  {
        try {            
            if(!file.exists()) {
                file.createNewFile(); // ´´½¨ÐÂÎļþ,ÓÐͬÃûµÄÎļþµÄ»°Ö±½Ó¸²¸Ç
            }
            //FileOutputStream¹¹Ô캯ÊýÖеĵڶþ¸ö²ÎÊýtrue±íʾÒÔ×·¼ÓÐÎʽдÎļþ 
            FileOutputStream fos = new FileOutputStream(file,fugai);
            OutputStreamWriter osw = new OutputStreamWriter(fos);
            BufferedWriter bw = new BufferedWriter(osw);
            bw.write(message);
            bw.newLine();
            bw.flush();
            bw.close();
            osw.close();
            fos.close();
        }catch (FileNotFoundException e1) {
            e1.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }
 
}