??xml version="1.0" encoding="utf-8" standalone="yes"?>
public String cutString(String str,int len){
byte[] a=str.getBytes();
byte[] b=new byte[len];
if(a.length>len){
System.arraycopy(a, 0, b, 0, len);
}
return new String(b);
}
]]>
/**
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
import java.io.*;
import java.text.*;
文档输出
*/
public static void billImagePdfGenerator(String pdfMsg, String brand, OutputStream output)
{
Document document = new Document(PageSize.A4);
String tempStr = "";
try
{
PdfWriter.getInstance(document, output);
document.open();
Image jpg = Image.getInstance("emice/jsp/images/bi" + brand + ".jpg");
jpg.scalePercent(80F);
document.add(jpg);
BufferedReader reader = null;
reader = new BufferedReader(new StringReader(pdfMsg));
while((tempStr = reader.readLine()) != null)
{
if(tempStr.startsWith("Page "))
document.newPage();
Phrase phrase = new Phrase(10F, tempStr + "\n", FontFactory.getFont("Courier", 9F));
document.add(phrase);
}
document.close();
reader.close();
}
catch(DocumentException de)
{
System.err.println(de.getMessage());
}
catch(IOException ioe)
{
System.err.println(ioe.getMessage());
}
}
/**
获取向前或者向后几天的日期
*/
public static final String getCaseFormatTime(int shiftDay)
{
Calendar cal = Calendar.getInstance();
int year = cal.get(1);
int month = cal.get(2);
int date = cal.get(5);
int hour = cal.get(11);
int minute = cal.get(12);
int second = cal.get(13);
date += shiftDay;
cal.set(year, month, date, hour, minute, second);
Date d = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
String dateString = sdf.format(d);
return dateString;
}
/**
获取当前旉
*/
public static final String getCurrentFormatDate()
{
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
String dateString = sdf.format(d);
return dateString;
}
/**
获取资源文g内容
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.PropertyMessageResourcesFactory;
*/
public static String getMessage(String resourceName, String messageName)
{
MessageResources resource = (new PropertyMessageResourcesFactory()).createResources(resourceName);
String value = resource.getMessage(messageName);
if(value == null)
value = "";
return value;
}
StringcdStringBuffer(StringBuilder)c?br>1 Stringcd象中的内容一但初始化׃能再改变?br>2 StringBuffercȝ于封装内容可以改变的字符丌Ӏ用toString()Ҏ(gu)转换成Stringcd?br>3 StringBuilderc?JDK1.5新加的类)实现了和StringBuffer的同L(fng)功能Q它的操作速度更快Q但它不保证多线E的安全性,所以如果它门不参与多线E推荐用StringBuilderc,而参与多U程推荐使用StringBufferc?
4 String中提供的一些改变内容的Ҏ(gu)Q实际上都是调用了StringBuffercȝҎ(gu)。String="a"+1+"b";~译时等效于String x=new StringBuffer().append("a").append(a).append("b").toString();
5 字符串常量,实际上是一中特D的匿名String对象Q用字W串帔R有时可以节省内存I间?br>String(byte[] bytes, int offset, int length) //构造函数将byte[]转换成stringcd
public String substring(int beginIndex,int endIndex)//从beginIndex开始截取到endIndex-1为止Q截取的长度为endIndex-beginIndex.
数据cd与包装类
boolean---Boolean byte---Byte char--Character short--Short int--Integer long--Long float--Float double--Double
基本数据cd不具有对象的Ҏ(gu),而包装类h对象的特性?br>String--->Integer的方?nbsp; new Integer(String str);Integer.valueOf(str);
Integer--->int的方?nbsp; Integer.intValue();
String--->int的三个方法,Integer.parseInt(str);new Integer(String str).intValue;Integer.valueOf(str).intValue();
int--->String String.valueOf(int);
集合c?br>集合cȝ于存储一l对象,其中的每个对象称之ؓ(f)元素Q经怼(x)用到的有Vector,Enumeration,ArrayList,Collection,Iterator,Set,List{集合类和接口。Enumeration,Collection,Iterator,set,Listq些接口不是集合c,而是提供了各U方法来操作集合cd象?/font>
VectorcMEnumeration接口
Vector v=new Vector;
Emumeration e=v.elements();
while(e.hasMoreElements())
{
e.nextElement();
}
Enumeration是个接口c,可以从各U数据类型中取出元素?/font>
Collection接口与Iterator接口?br>ArraryList是实现Collection接口的类?br>ArrayList与Vector的区?
ArrayList没有实现U程的同步,而Vector实现了线E的同步Q但ArrayList的执行效率比Vector高,所以程序不存在U程安全问题时应使用ArrayList.
Collection,Set,List的区别:(x)
Collection是Set,List的父c,Collection各元素对象之间没有指定的序Q允许有重复元素和多个null元素对象?br>Set各元素对象之间没有指定的序Q不允许有重复元素,最多允许有一个叫null的元素对象?br>List各元素对象之间有指定的顺序,允许有重复元素和多个null元素对象?/font>
Hashtablec?br>Hashtable是高U数据结构,可以快速检索数据,动态存储一pd的对象,对存储的每一个对??都要安排另一个对?UCؓ(f)关键?与之相关联?br>存储数据:Hashtable.put(Object key,Object value) 值和关键字可一是Q何非I的对象。存储数据时如关键字相同Q则原来的那个D覆盖掉?br>(g)索数?Hashtable.get(Object key) 用作关键字的cd覆盖Object.hashCodeҎ(gu)和Object.equalsҎ(gu).
StringcȝhashCode已经覆盖了关键字cȝhashCodeQ只要两个字W串相等Q他们的hashCode也相{。但StringBuffercL有覆盖关键字cȝhashCode.
Propertiesc?br>1 PropetiescLHashtable的子c?br>2 增加了将Hashtable对象中的关键字和g存到文g和从文g中读取关键字和值到Hashtable对象中的Ҏ(gu)?br>3 如果要用Properties.store(FileOutputStream out,String str)Ҏ(gu)存储Properties对象中的内容Q每个属性的关键字和值多必须是Stringcd的。从文g中装载数据用的是Properties.load()Ҏ(gu)?br>4 Properties.get()Ҏ(gu)q回的是Objectcd的,Properties.getProperty(..)q回的是Stringcd的。Properties.setProperty(...)的参数类型必LStringcd.(取得或设|Properties中的?
System与Runtimec?br>SystemcM所有的成员都是静态的Q?br>1 exit(int status)提前l止虚拟机的q行Q正常操作传递的参数?Q异常终止传递的是非零倹{?br>2 currentTimeMillisҎ(gu)q回的是一个自1970q?????Uv的以毫秒为单位的long 型的大数字?br>3 Java虚拟机的pȝ属性:(x)System.getProperties()和System.setProperties()Ҏ(gu)分别取得和设|Java虚拟机的pȝ属性。Enumeration e=System.getProperties().propertyNames();
Runtimec?br>装了Java虚拟E,一个Java虚拟机对应一个Runtime实例对象Q不能直接创Z个对象,通过Runtime.getRuntime()Ҏ(gu)q回一个Runtime的实例对象的引用。用execҎ(gu)可以启动一个子q程q回的是一个Process的对象。例QProcess p=Runtime.getRuntime().exec("notepad.exe Test.java");参数E名和用该进E打开文g名?/font>
public static void readFile(){
try{
File file = new File("D:\\dosp\\t.txt");
java.io.FileReader reader = new FileReader(file);
BufferedReader br = new BufferedReader(reader);
String s = br.readLine();
System.out.println(" s = " + s);
replaceChar(s);
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
Test test = new Test();
readFile();
}
以下是在文本t.txt中的例子(处于一?每个字段用引h?各个字段之间有空?
"01282356000280118304" "01" "0" " " "923084" "13466390573" "5198 " "-GSSP " "03" "0 " "1500 " "DB:0115" "1" "101" " " "002801" " " "13800280500" "20070128235602" "20070128235602" "Agent0" "0 "
q过上面函数处理后得?
W一步得?
"01282356000280118304010 923084134663905735198 -GSSP 030 1500 DB:01151101 002801 138002805002007012823560220070128235602Agent00 "
W二步得?
01282356000280118304010 923084134663905735198 -GSSP 030 1500 DB:01151101 002801 138002805002007012823560220070128235602Agent00
int lastIndex = sql.lastIndexOf("'");
if ( lastIndex < 0 )
return sql;
if ( 0 == lastIndex )
return "'" + sql;
int[] sepIndexArray = new int[lastIndex + 1 + 2];
sepIndexArray[0] = 0;
int startIndex = -1;
int sepIndex = 1;
while ( (startIndex = sql.indexOf("'", startIndex + 1)) >= 0 )
sepIndexArray[sepIndex++] = startIndex;
sepIndexArray[sepIndex] = sql.length();
String result = sql.substring(sepIndexArray[0], sepIndexArray[1]);
for ( int i = 1; i < sepIndex; i++ )
result = result
+ "'" + sql.substring(sepIndexArray[i], sepIndexArray[i + 1]);
return result;
}