预览加载中,请您耐心等待几秒...
1/4
2/4
3/4
4/4

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

packagecom.zmw.framework.common.util; importjava.io.BufferedReader; importjava.io.BufferedWriter; importjava.io.File; importjava.io.FileInputStream; importjava.io.FileOutputStream; importjava.io.FileWriter; importjava.io.IOException; importjava.io.InputStreamReader; importorg.apache.log4j.Logger; publicclassAccessTokenTxt{ Stringaccess_token=""; publicvoidwriteFile(Stringkey)throwsIOException { this.access_token=key; try { StringrootPath=System.getProperty("user.dir");//系统指定根目录/mnt/hljproject/tomcat/bin/demo.txt StringfilePath=null; if(rootPath.endsWith("/")){ filePath=rootPath+"demo.txt"; }else{ filePath=rootPath+"/demo.txt"; } Filedir=newFile(filePath); FileWriterfw=newFileWriter(dir); BufferedWriterbw=newBufferedWriter(fw); bw.write(access_token.trim()); bw.flush(); Logger.getLogger("wxpay").info("写入缓存,缓存地址["+filePath+"]-Access_token["+access_token+"]"); }catch(Exceptionex){ Logger.getLogger("wxpay").info("写入缓存异常"); } } publicStringreaderFile()throwsIOException { Stringaccess_token=""; StringfilePath=System.getProperty("user.dir")+"/demo.txt"; FileInputStreamfis=null; try { fis=newFileInputStream(filePath); InputStreamReaderreader=newInputStreamReader(fis,"UTF-8"); BufferedReaderbr=newBufferedReader(reader); Stringinfo=""; while((info=br.readLine())!=null){ access_token=info; } br.close(); fis.close(); Logger.getLogger("wxpay").info("读取缓存,缓存地址["+filePath+"]-Access_token["+access_token+"]"); returnaccess_token; }catch(Exceptionex){ Logger.getLogger("wxpay").info("读取缓存异常"); returnnull; } } publicvoidclearFileContent()throwsIOException { StringfilePath=System.getProperty("user.dir")+"/demo.txt"; try { FileOutputStreamout=newFileOutputStream(filePath,false); out.write(newString("").getBytes()); out.close(); }catch(Exceptionex){ Logger.getLogger("wxpay").info("清空缓存异常"); } } }