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的更多相关文章

  1. com.velocity.servlet

    package com.velocity.servlet; import java.io.IOException; import java.util.ArrayList; import java.ut ...

  2. com.service.impl

    package com.service.impl; import java.util.ArrayList; import java.util.LinkedHashMap; import java.ut ...

随机推荐

  1. 如何卸载eclipse中的ADT

    卸载ADT的方法,方法如下: 1.选择 Help > Install New Software: 2.在"Details" 面板中, 点击"What is alre ...

  2. 我的web小游戏【持续更新中】

    在谷歌浏览器中实测无问题.. 五子棋(双人对战):http://1.waymongame.sinaapp.com/wuziqi/wuziqi2.html 贪吃蛇:http://1.waymongame ...

  3. memcache redundancy机制分析及思考

    设计和开发可以掌控客户端的分布式服务端程序是件幸事,可以把很多事情交给客户端来做,而且可以做的很优雅.角色决定命运,在互联网架构中,web server必须冲锋在前,注定要在多浏览器版本以及协议兼容性 ...

  4. 最短路径算法Dijkstra和A*

    在设计基于地图的游戏,特别是isometric斜45度视角游戏时,几乎必须要用到最短路径算法.Dijkstra算法是寻找当前最优路径(距离原点最近),如果遇到更短的路径,则修改路径(边松弛). Ast ...

  5. KMP算法详解 --从july那学的

    KMP代码: int KmpSearch(char* s, char* p) { ; ; int sLen = strlen(s); int pLen = strlen(p); while (i &l ...

  6. php 仿百度文库

    http://www.haosblog.com/?mod=article_read&id=386

  7. 跨平台的游戏客户端Socket封装,调整

    原文链接:http://www.cnblogs.com/lancidie/archive/2013/04/13/3019359.html 头文件: #pragma once #ifdef WIN32 ...

  8. 【Hadoop代码笔记】通过JobClient对Jobtracker的调用详细了解Hadoop RPC

    Hadoop的各个服务间,客户端和服务间的交互采用RPC方式.关于这种机制介绍的资源很多,也不难理解,这里不做背景介绍.只是尝试从Jobclient向JobTracker提交作业这个最简单的客户端服务 ...

  9. HDU-4699 Editor 数据结构维护

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4699 题意:开始有一个光标,每次有5中操作:1,光标当前位置插入一个数,2,光标当前位置删除一个,3, ...

  10. 在KVM虚拟机中使用spice系列之二(USB映射,SSL,密码,多客户端支持)

    在KVM虚拟机中使用spice系列之二(USB映射,SSL,密码,多客户端支持) 发布时间: 2015-02-27 00:16 1.spice的USB重定向 1.1 介绍 使用usb重定向,在clie ...