IO流的使用,自己的心得
/**
* 用缓存的字节入做写入操作
*
*/
@Test
public void testOutPut(){
String filePath = "F://test1.txt";
String writeString = "testOutPut:1231";
int tempLength = 2;
StringBuffer bs = new StringBuffer();
int each = 0;
try {
ops = new FileOutputStream(filePath);
byte writeStringToBytes[] = writeString.getBytes();
byte temp[] = new byte[tempLength];
//需要几次写入
if(writeStringToBytes.length%tempLength==0)
each = writeStringToBytes.length/tempLength;
else
each = writeStringToBytes.length/tempLength+1;
//每一次写入流
for(int i=0;i<each;i++){
if(i==(each-1)&&writeStringToBytes.length%tempLength!=0){
System.arraycopy(writeStringToBytes, i*tempLength, temp, 0, writeStringToBytes.length%tempLength);
ops.write(new String(temp,"GBK").trim().getBytes(),0,writeStringToBytes.length%tempLength);
bs.append(new String(temp,0,writeStringToBytes.length%tempLength,"GBK"));
}else{
System.arraycopy(writeStringToBytes, i*tempLength, temp, 0, tempLength);
ops.write(new String(temp,"GBK").trim().getBytes());
bs.append(new String(temp,"GBK"));
}
}
// System.out.println(bs.toString().trim());
// ops.write(writeStringToBytes);
ops.flush();
ops.close();
// System.out.println("bs=="+bs.toString().trim());
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("each="+each);
}
struts2.0学习系列
在JSP中使用Struts 2.0标志,先要指明标志的引入。通过在JSP的代码的顶部加入以下代码可以做到这点。
<%@taglib prefix="s" uri="/struts-tags" %>
一步步讲起
对初学者非常容易上手