java 文件的读写操作
java 文件的读写操作
一.读:
public String getSetting() {
HttpServletRequest request=org.apache.struts2.ServletActionContext.getRequest();
String maxNum = ConfigManager.instance().getProperty("setting", "maxNum");
String startTime = ConfigManager.instance().getProperty("setting",
"startTime");
String endTime = ConfigManager.instance()
.getProperty("setting", "endTime");
if(maxNum==null ||maxNum==""){
maxNum=getMaxNum();
}
if(startTime==null ||startTime==""){
maxNum=getStartTime();
}
if(endTime==null ||endTime==""){
endTime=getEndTime();
}
setMaxNum(maxNum);
setStartTime(startTime);
setEndTime(endTime);
request.setAttribute("maxNum", maxNum);
request.setAttribute("startTime", startTime);
request.setAttribute("endTime", endTime);
return "settingsHandle";
}
二.写:
public String setSetting() {
HttpServletRequest request=org.apache.struts2.ServletActionContext.getRequest();
String maxNum = ParamUtil.getString(request, "maxNum");
String startTime = ParamUtil.getString(request, "startTime");
String endTime = ParamUtil.getString(request, "endTime");
String filePath=SettingsAction.class.getResource("/setting.properties").getPath();
java.util.Properties prop = new java.util.Properties();
try {
InputStream fis = new FileInputStream(filePath);
//从输入流中读取属性列表(键和元素对)
prop.load(fis);
//调用 Hashtable 的方法 put。使用 getProperty 方法提供并行性。
//强制要求为属性的键和值使用字符串。返回值是 Hashtable 调用 put 的结果。
OutputStream fos = new FileOutputStream(filePath);
prop.setProperty("maxNum", maxNum);
prop.setProperty("startTime", startTime);
prop.setProperty("endTime",endTime);
//以适合使用 load 方法加载到 Properties 表中的格式,
//将此 Properties 表中的属性列表(键和元素对)写入输出流
prop.store(fos,"最大条数");
prop.store(fos,"开始时间");
prop.store(fos,"结束时间");
return "ok";
} catch (IOException e) {
System.err.println("no");
return "no";
}
}
java 文件的读写操作的更多相关文章
- java文件的读写操作
java文件的读写操作主要是对输入流和输出流的操作,由于流的分类很多,所以概念很容易模糊,基于此,对于流的读写操作做一个小结. 1.根据数据的流向来分: 输出流:是用来写数据的,是由程序(内存)--- ...
- Java 对不同类型的数据文件的读写操作整合器[JSON,XML,CSV]-[经过设计模式改造](2020年寒假小目标03)
日期:2020.01.16 博客期:125 星期四 我想说想要构造这样一个通用文件读写器确实不容易,嗯~以后会添加更多的文件类型,先来熟悉一下文件内容样式: <?xml version=&quo ...
- android报错及解决2--Sdcard进行文件的读写操作报的异常
报错描述: 对Sdcard进行文件的读写操作的时候,报java.io.FileNotFoundException: /sdcard/testsd.txt (Permission denied),在往S ...
- 使用字符流(Writer、Reader)完成对文件的读写操作
字符流 字符输出流:Writer,对文件的操作使用子类FileWriter 字符输入流:Reader,对文件的操作使用子类FileReader 每次操作的是一个字符 文件字符操作流会自带缓存,默认大小 ...
- INI 文件的读写操作
在C#中对INI文件进行读写操作,在此要引入using System.Runtime.InteropServices; 命名空间,具体方法如下: #region 变量 private static r ...
- Android 对 properties文件的读写操作
-. 放在res中的properties文件的读取,例如对放在assets目录中的setting.properties的读取:PS:之所以这里只是有读取操作,而没有写的操作,是因为我发现不能对res下 ...
- C++学习48 对ASCII文件的读写操作
如果文件的每一个字节中均以ASCII代码形式存放数据,即一个字节存放一个字符,这个文件就是ASCII文件(或称字符文件).程序可以从ASCII文件中读入若干个字符,也可以向它输出一些字符. 对ASCI ...
- Delphi- ini文件的读写操作
一.读INI文件示例 procedure TForm1.FormCreate(Sender: TObject); Var MyIni :Tinifile; glAppPath :string; beg ...
- python使用装饰器对文件进行读写操作'及遍历文件目录
'''使用装饰器对文件进行读写操作''' # def check_permission(func): # '''演示嵌套函数定义及使用''' # def wrapper(*args,**kwargs) ...
随机推荐
- Spring Boot基本配置
本文参考javaEE开发的颠覆者SpringBoot实战第一版 基本配置 入口类和@SpringBootApplication Spring Boot通常有一个名为*Application的入口类,且 ...
- MySQL 使用pt-table-checksum 检查主从数据一致性 (实例转)
1.基本环境: Mysql版本:5.6.12-log Percona-toolkit:2.2.18 Linux:centos6.5 2.安装 源码安装: # 一些依赖包 yum install per ...
- SSL与TLS的区别
SSL(Secure Socket Layer 安全套接层)是基于HTTPS下的一个协议加密层,最初是由网景公司(Netscape)研发,后被IETF(The Internet Engineering ...
- Maven Build错误。
错误: No goals have been specified for this build. You must specify a valid lifecycle phase or a goal ...
- 2017-09-17 python 学习笔记
Mock 库 介绍: http://blog.csdn.net/chdhust/article/details/50663729 说明mock能做什么. 可以考虑在调试方法时使用 Mock 库
- 管理react路由的history对象的插件history的使用介绍
本文介绍如何使用history插件管理浏览记录 history插件的使用 history这个插件可以方便管理你的浏览记录 cnpm install history --save import crea ...
- VMware:Configuration file was created by a VMware product with more features than this version
Few days ago,I opened the Genesys demo VM by VMware Server 1.0.4 and got an error like this: "C ...
- javascipt——对象的概念——数组
一.Array 特点: 数组的长度是可变的: 数组的索引可以是数字.字符串: 数组的内容可以是任意内容: 可以通过索引获取之前不存在的一个位置,其值为undefined: 1.构造函数: new Ar ...
- Quartz_1_简单编程式任务调度使用(SimpleTrigger)
最近在工作中,要做定时任务的更能,最开始的时候,想到的是 JavaSE 中,自带 Timer 及 TimerTask 联合使用,完成定时任务.最后发现,随着业务的复杂,JDK 中的 Timer 和 T ...
- PHP算法
一,实现快速排序 <?php function quickSort($arr) { $len=count($arr) ; if($len<=1) { return $arr; } $key ...