星期四, 八月 09, 2007

生成文件树

3.在命令提示符窗口中输入以下命令,如图2所示。

  dir d:\ >c:\filelist.txt

小技巧:用DOS命令生成光盘文件列表

图2 用此命令生成列表文件

  这样就在C:盘根目录下生成了一个名为"filelist.txt"的文本文件,该文件中即包含D:盘的文件夹列表。

  如果希望将D:盘中子目录中的文件和文件夹列表也全部列出来,可以在命令提示符窗口中输入以下命令。

  dir d:\ /s >c:\filelist.txt

  如果使用下面的命令,即加一个/b,则会生成一个简单的文件名列表,不包括其它信息,这种方法可能更加实用一些。

  dir d:\ /s /b >c:\filelist.txt

  生成文本文件后,就可以将该文件中的内容拷贝到Excel中以备日后查询,或者将该文件作为一个对象插入到Excel工作表中。这样以后就可以快速找到所需要的光盘了。

 

1、命令 dir *.*/b/s > filelist.txt
生成的文件格式:
X:\XXX\A.XXX
X:\XXX\B.XXX
...

2、命令 dir *.*/b > filelist.txt
生成的文件格式:
A.XXX
B.XXX
...

3、命令 dir *.*/s > filelist.txt
生成的文件格式:
驱动器 X 中的卷是 ASOFT
卷的序列号是 18A2-30C9

X:\XXX 的目录

2005-01-13 19:46 3,739,854 A.XXX
2005-01-13 19:45 3,924,174 B.XXX
...
170 个文件 704,193,612 字节
0 个目录 2,889,695,232 可用字节

4、命令 dir *.*/b > filelist.txt
生成的文件格式:
同3

5、命令 tree/f > X:\tree.txt
可以生成树形文件结构,适合做层次分明的文件结构清单,比如网站内容清单等

星期三, 八月 08, 2007

星期三, 八月 01, 2007

StringUtil


package sample;

import java.util.StringTokenizer;
/**

  * StringUtil
  */
public class StringUtil {
         /**
          * 文字列の分割(区切り文字指定)
          * @param str 対象文字列
          * @param delim 区切り文字列
          * @return 分割後の文字列
          */
         public static String[] split(String str, String delim) {
                  StringTokenizer st = new StringTokenizer(str, delim);
                  int length = st.countTokens();
                  String[] result = new String[length];
                  for (int i = 0; i < length; i++) {
                      result[i] = st.nextToken();
                  }
                  return result;
         }

}

星期四, 七月 19, 2007

PreparedStatement和Statement

preparedstatement 优点
 
1,安全
2,对于重复数据,速度快
3,对了重复数据,占用服务器的pool少
 
Statement优点
 
1,利于编程,拼sql简单
2,对于一次性执行,比preparedstatement快

星期二, 七月 03, 2007

copy file

package test;

import java.io.File;
import java.io.IOException;
import java.util.Calendar;


public class test {

 
 public static void main(String args[]) {
  String filename1 = "C:\\1";
  String filename2 = "C:\\2";
  test test1 = new test();
  try{
  test1.copyFileByPath(filename1, filename2);
  }catch (Exception e) {
   // TODO: handle exception
  }
 }
 
 public void copyFileByPath(String scrPathName,String targetPathName)
  throws NullPointerException,IOException, Exception {
  try{
   File scrPath = new File(scrPathName);
   File targetPath = new File(targetPathName);
   copyFileByPath(scrPath, targetPath);
  }catch (NullPointerException e) {
   //logger.error(dir.getName() + " folder is not exist", e);
   throw e;
  } catch (IOException e) {
   //logger.error(e.getMessage(),e);
   throw e;
  }catch (Exception e) {
   //logger.error(e.getMessage(), e);
   throw e;
  }
 }
 public void copyFileByPath(File scrPath,File targetPath)
  throws NullPointerException,IOException, Exception {
  try {
   String[] fs = scrPath.list();

   for (int i = 0; i < fs.length; i++) {
    File fis = new File(scrPath, fs[i]);
    long currentTime = Calendar.getInstance().getTimeInMillis();
    if (fis.isFile()&&fis.lastModified()<(currentTime-1000*60*1)) {
     copyFile(fis, targetPath);
    } else if (fis.isDirectory()) {
     copyFileByPath(fis, targetPath);
    }
   }
  } catch (NullPointerException e) {
   //logger.error(dir.getName() + " folder is not exist", e);
   throw e;
  } catch (IOException e) {
   //logger.error(e.getMessage(),e);
   throw e;
  }catch (Exception e) {
   //logger.error(e.getMessage(), e);
   throw e;
  }
 }
 
 public void copyFile(File scrFile,File targetPath){
  long lastModifiedTime = scrFile.lastModified();
  
  try{
  File targetFile = new File(targetPath,scrFile.getName());
  java.io.FileInputStream in =new java.io.FileInputStream(scrFile);
     java.io.FileOutputStream out =new java.io.FileOutputStream(targetFile);
     byte Buff[]=new byte[1024];
     int len;
     while((len=in.read(Buff))>-1){
       out.write(Buff,0,len);
     }
     in.close();
     out.close ();
     targetFile.setLastModified(lastModifiedTime);
  }catch (Exception e) {
   // TODO: handle exception
  }
 }
}