com.ulitis.www
package com.ulitis.www; import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; public class JUtils { // Read one from Spec Layout
public static String readFromFile(String filename)
throws FileNotFoundException, IOException {
FileInputStream fis = new FileInputStream(filename);
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr);
// 简写如下
// BufferedReader br = new BufferedReader(new InputStreamReader(
// new FileInputStream("E:/phsftp/evdokey/evdokey_201103221556.txt"),
// "UTF-8"));
String line = "";
String arrs = null;
while ((line = br.readLine()) != null) {
arrs += line;
}
br.close();
isr.close();
fis.close();
return arrs;
} public static void write(String path, String content) {
String s = new String();
String s1 = new String(); try {
File f = new File(path); if (f.exists()) {
System.out.println("文件存在");
if (f.delete()) {
f.createNewFile();
System.out.println("文件删除成功!");
} else {
System.out.println("文件删除失败!");
} } else {
System.out.println("文件不存在,正在创建...");
if (f.createNewFile()) {
System.out.println("文件创建成功!");
} else {
System.out.println("文件创建失败!");
}
} BufferedReader input = new BufferedReader(new FileReader(f)); while ((s = input.readLine()) != null) {
s1 += s + "/n"; } input.close();
s1 += content;
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s1);
output.close();
} catch (Exception e) {
e.printStackTrace();
}
} // format for if condition
public static String getFormat(int i) {
return i + "****";
} }
package com.ulitis.www; import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties; public class PropertiesUnit {
private static LinkedHashMap<String,String> map = new LinkedHashMap<String,String>();
public static String readValue(String filePath,String key) {
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
props.load(in);
String value = props.getProperty (key);
System.out.println(key+value);
return value;
} catch (Exception e) {
e.printStackTrace();
return null;
}
} //读取properties的全部信息
public static LinkedHashMap<String, String> readProperties(String filePath) {
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
props.load(in);
Enumeration en = props.propertyNames();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String Property = props.getProperty (key); map.put(key, Property); }
} catch (Exception e) {
e.printStackTrace();
}
return map;
} //写入properties信息
public static void writeProperties(String filePath,String parameterName,String parameterValue) {
Properties prop = new Properties();
try {
InputStream fis = new FileInputStream(filePath);
//从输入流中读取属性列表(键和元素对)
prop.load(fis);
//调用 Hashtable 的方法 put。使用 getProperty 方法提供并行性。
//强制要求为属性的键和值使用字符串。返回值是 Hashtable 调用 put 的结果。
OutputStream fos = new FileOutputStream(filePath);
prop.setProperty(parameterName, parameterValue);
//以适合使用 load 方法加载到 Properties 表中的格式,
//将此 Properties 表中的属性列表(键和元素对)写入输出流
prop.store(fos, "Update '" + parameterName + "' value");
} catch (IOException e) {
System.err.println("Visit "+filePath+" for updating "+parameterName+" value error");
}
} }
com.ulitis.www的更多相关文章
- com.velocity.servlet
package com.velocity.servlet; import java.io.IOException; import java.util.ArrayList; import java.ut ...
- com.service.impl
package com.service.impl; import java.util.ArrayList; import java.util.LinkedHashMap; import java.ut ...
随机推荐
- UpYun上传 401 Unauthorized
_upt=3b9b444a14059041252014-07-21 08:46:25,218 ERROR (com.UpYun:518) - Upload file error:<h1>4 ...
- C#第三方控件的使用
一.DEVEXPRESS的使用 官网:https://www.devexpress.com/ 入门教程:http://wenku.baidu.com/link?url=2sXEEby1ffx9JTWG ...
- Google Maps API v2 Demo Tutorial
申请API KEY https://code.google.com/apis/console/?noredirect 1. 创建项目,名称随意,只是为了区分 2. 开启Google Maps Andr ...
- 黑盒测试用例设计方法&理论结合实际 -> 等价类划分
一. 概念 等价类划分法是把程序的输入域划分成若干部分(子集),然后从每个部分中选取少数代表性数据作为测试用例.每一类的代表性数据在测试中的作用等价于这一类中的其他值. 二. 等价类划分的应用 等价类 ...
- mac远程连接 win8
首先 打开组策略 .windows8 下 按win+R 可以唤出运行,输入[gpedit.msc]按下 回车键 选择[计算机配置]>[管理模板]>[Windows组件]>[远程桌面服 ...
- SqlServer中截取字符串
SQL Server 中截取字符串常用的函数: .LEFT ( character_expression , integer_expression ) 函数说明:LEFT ( '源字符串' , '要截 ...
- REST和SOAP
转自:http://blog.csdn.net/smstong/article/details/5312136 我感觉维基百科说的REST解释的就听明白的,摘录下来: 含状态传输(英文:Represe ...
- 2015北京网络赛A题The Cats' Feeding Spots
题意:给你一百个点,找个以这些点为中心的最小的圆,使得这个圆恰好包含了n个点,而且这个圆的边界上并没有点 解题思路:暴力枚举每个点,求出每个点到其他点的距离,取第n大的点,判断一下. #include ...
- javascript设计模式3
门户大开式对象 var Book=function(isbn,title,author){ if (isbn==undefined) throw new Error("不合法"); ...
- cocos2d-x的helloLua例子函数名定义误导初学者
初次研究cocos2d-x, cocos2d-x支持lua是一个很不错的功能,使用lua来开发有个最大的好处就是不用每次改了游戏代码都编译,大多数情况下改了脚本直接运行程序就可以了,发布更新时也不用更 ...