N長時間沒有來了.......
忙中偷閑,整理點(diǎn)代碼。
/**
* 復(fù)制單個文件
* @param oldPath String 原文件路徑 如:c:/fqf.txt
* @param newPath String 復(fù)制后路徑 如:f:/fqf.txt
* @return boolean
*/
public void copyFile(String oldPath, String newPath)
{
try {
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件存在時
InputStream inStream = new FileInputStream(oldPath); //讀入原文件
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];
int length;
while ( (byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //字節(jié)數(shù) 文件大小
System.out.println(bytesum);
fs.write(buffer, 0, byteread);
}
inStream.close();
}
}
catch (Exception e) {
System.out.println("復(fù)制單個文件操作出錯");
e.printStackTrace();
}
}
//保存文件的方法
public String Savefiles(FormFile file,String path)
{
String fileName= file.getFileName();
String contentType = file.getContentType();
String size = (file.getFileSize() + " bytes");
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream stream = file.getInputStream();
OutputStream bos = new FileOutputStream(path+fileName);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
stream.close();
}
catch (IOException e) {
return e.getMessage();
}
return "1";
}
//生成15位的字符串
public String GenTradeId()
{
String tradeId = "";
RandomStrg.setCharset("a-zA-Z0-9");
RandomStrg.setLength("15");
try
{
RandomStrg.generateRandomObject();
tradeId=RandomStrg.getRandom();
}
catch (Exception e)
{
}
return tradeId;
}
/**
* 刪除字符串中的空格,至多只保留一個空格
*
* @String txt:輸入需要處理的字符串
* @return String :返回處理后的字符串
*
*/
public String deleteWhitespace(String txt){
if((txt!=null)&&(txt.trim().length()>1)){
}
else{
return "";
}
txt = txt.replaceAll("\n"," ").replaceAll("\t"," ");
String temp="";
try{
int flag =0,num=0;
char c = 'x';
StringBuffer sb = new StringBuffer("");
for(int x=0;x<txt.length();x++){
c = txt.charAt(x);
if((c==' ')&&(flag==0)){
sb.append(c);
flag =1;
}
else if((c!=' ')){
sb.append(c);
flag =0;
}
}
temp = sb.toString().trim();
}
catch(Exception e){
;
}
return temp;
}
摘要: 1.文本框焦點(diǎn)問題onBlur:當(dāng)失去輸入焦點(diǎn)后產(chǎn)生該事件onFocus:當(dāng)輸入獲得焦點(diǎn)后,產(chǎn)生該文件Onchange:當(dāng)文字值改變時,產(chǎn)生該事件Onselect:當(dāng)文字加亮后,產(chǎn)生該文件
<input type="text" value="郭強(qiáng)" onfocus="if(value=='郭強(qiáng)') {value=''}" onblur="if (value=='')... 閱讀全文