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. iOS开发中提交带有中文或特殊字符串的参数

    iOS开发中,与后台进行数据交换是一个很常见的场景. 在web开发中,对于我们提交的地址,浏览器会负责进行decode,但是在ios中,必须要自己手动来实现.否则我们拼接出的网址在包括中文.特殊字符串 ...

  2. u-boot 环境变量参数设置

    今天本来是烧写内核,结果一不小心把uboot也整不能用了,无奈之下只好重新烧个uboot,等都弄好以后,发现系统还是启动不了,原来是启动参数设置不对,于是找到了这篇文章,//是我添加的内容. 原文地址 ...

  3. 软件测试模型汇总-V模型,W模型,X模型,H模型

    V模型 在软件测试方面,V模型是最广为人知的模型,尽管很多富有实际经验的测试人员还是不太熟悉V模型,或者其它的模型.V模型已存在了很长时间,和瀑布开发模型有着一些共同的特性,由此也和瀑布模型一样地受到 ...

  4. java基础之数据类型转换

    在写java程序时,经常会遇到需要数据类型转换,下面我们来介绍一些一些基本数据类型之间的转换. 1.int,folat,double,boolean,long 转换成字符串,其实很简单只需使用一个函数 ...

  5. 【转】Qt Creator在Windows上的调试器安装与配置

    https://www.librehat.com/qt-creator-on-windows-debugger-installation-and-configuration/

  6. case中定义变量

    1.c语言switch/case中定义变量   case 0: int b = 0 ; printf("0");break; case 1: printf("1" ...

  7. Poj 2081 Recaman's Sequence之解题报告

                                                                                                         ...

  8. jQuery中实现自定义方法的扩展

    JQuery包装器提供了大量的方法,可以再页面中直接使用.但是,没有 任何一个库可以满足所有的需求,所以,JQuery库提供了丰富的扩展功能 .以禁用一组表单元素为例,看看怎么简单有效的在JQuery ...

  9. bzoj 1060 [ZJOI2007]时态同步(树形DP)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1060 [题意] 求最少的增加量,使得以rt为根的树中由一个结点出发的所有到叶子结点的路 ...

  10. Android Socket 相关

    http://www.imooc.com/learn/223 http://www.epubit.com.cn/book/onlinechapter/12093