大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> JSP专区 -> jsp计数器制作手册(2)

jsp计数器制作手册(2)

时间: 2021-07-31 作者:daque

//counter.java 读写文献的一个beanimport java.io.*;public class counter extends object {private string currentrecord = null;//生存文本的变量private bufferedreader file; //bufferedreader东西,用来读取文献数据private string path;//文献完备路途名public counter() {}//readfile本领用来读取文献filepath中的数据,并归来这个数据public string readfile(string filepath) throws filenotfoundexception{path = filepath;//创造新的bufferedreader东西file = new bufferedreader(new filereader(path));string returnstr =null;try{//读取一条龙数据并生存到currentrecord变量中currentrecord = file.readline();}catch (ioexception e){//缺点处置system.out.println("读取数据缺点.");}if (currentrecord == null)//即使文献为空returnstr = "没有任何记载";else{//文献不为空returnstr =currentrecord;}//归来读取文献的数据return returnstr;}//readfile本领用来将数据counter+1后写入到文本文献filepath中//以实行计数延长的功效public void writefile(string filepath,string counter) throws filenotfoundexception{path = filepath;//将counter变换为int典型并加一int writestr = integer.parseint(counter)+1;try {//创造printwriter东西,用来写入数据到文献中printwriter pw = new printwriter(new fileoutputstream(filepath));//用文本方法打字与印刷平头writestrpw.println(writestr);//废除printwriter东西pw.close();} catch(ioexception e) {//缺点处置system.out.println("写入文献缺点"+e.getmessage());}}}  到这边,步调写结束,将counter.java编写翻译为counter.class,同样放在对应的class目次下,在根目次下创造一个lyfcount.txt文献,文献实质就一个数字0,径直在欣赏器中敲入地方就不妨看到计数器了,革新欣赏器会看到连接变换的数字。  (即使运转功夫提醒找不到文献,请将上头test.jsp中的readfile那一句解释后运转一次则lyfcount.txt文献机动创造,而后就不妨平常运转。)

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.