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();
|
}
|
}
|
}
|