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
package IDcardManage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
/**´ËÀàΪ¶Á´æÈ¡ÎļþÀà*/
public class ReadFiles {
       static String txt;
       static File file;
       public static String readFiletxt(String filepath) throws IOException {
           file= new File(filepath);//Îļþ·¾¶´ú±íÎļþ·¾¶µØÖ·
            //Èç¹ûÎļþ²»´æÔھʹ´½¨Ò»¸öÎļþ
            if(!file.exists()) {
                file.createNewFile();
            }
            FileInputStream filein = new FileInputStream(file);//ÎļþÊäÈë×Ö½ÚÁ÷
           int size = filein.available();//¿É¶ÁµÄ×Ö½ÚÊý×鳤¶È
            byte byt[]=new byte[size ];//´´½¨byteÊý×鳤¶Èsize
            int length = 0;            
            while((length=filein.read(byt))!= -1){   
                txt=new String(byt,0,length);;
            }
            
            filein.close();//¹Ø±ÕÎļþÁ÷
            
            return txt;        
       
}
       
       /**±£´æÎı¾µÄ·½·¨*/
    public static void wirteTxt(String filepath,String txt) { //±£´æÎı¾·½·¨
    try {
        file= new File(filepath);//Îļþ·¾¶´ú±íÎļþ·¾¶µØÖ· 
        FileWriter out=new FileWriter(file);//ÎļþÊä³ö×Ö·ûÁ÷
        if(!file.exists()) {
            file.createNewFile();
        }
        out.write(txt);
        out.close();
    } catch (IOException e1) {                        
        e1.printStackTrace();
    }    
    }    
}