test

============ the file name: FileTest.java
package test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.io.IOException;

public class FileTest {
 
 public static void main(String[] args) throws IOException, Exception {
  
  long startTime = System.currentTimeMillis();
  File f = new File("test");
  File[] files = f.listFiles();
  FileInputStream fi = null;
  File outFile = new File(f.getAbsolutePath().replace("\\", "") + ".txt");
  if(!outFile.exists())
   outFile.createNewFile();
  FileOutputStream fo = new FileOutputStream(outFile);
//  StringBuffer sb;
  int length = 0;
  for(File file: files){
   fi = new FileInputStream(file);
   length =fi.available();
   byte[] content = new byte[length];
   fi.read(content);
   fo.write(content);

   System.out.println("============ the file name: " + file.getName());
   System.out.println(new String(content));
  }
  fi.close();
  fo.close();
   Thread th = new Thread();
//  th.sleep(100);
  
  System.out.println("the threda's name: " + th.getName() + th.getThreadGroup() + "   toString: " + th.toString());
//  int sum = 0;
//  for(int i = 0;i<100000;i++){
//   sum +=i;
//  }
//  System.out.println(sum);
  System.out.println(System.currentTimeMillis() - startTime);
  
 }
}

============ the file name: MyApplet.java

 

============ the file name: NewFile.xml

============ the file name: SendMail.java
package test;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;


public class sendMail
{
public static void main(String args[]) throws Exception
{

String host = "smtp.sina.com.cn";
String from = "javamail@sina.com";
String to = "javamail@china.com";
String username = "javamail";
String password = "password";

// Get system properties
// Properties props = System.getProperties(); 很多例子中是这样的,其实下面这句更好,可以用在applet中
Properties props = new Properties();

// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true"); // 这样才能通过验证

// Get session
Session session = Session.getDefaultInstance(props);

// watch the mail commands go by to the mail server
session.setDebug(true);

// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");

// Send message
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}

============ the file name: Test.java
package test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

enum MyColor {
 Red, Yellow, Blue , s,fsd,f,dsf,ee,
}

public class Test {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub

  
  MyColor color = MyColor.f;
  System.out.println(color);
  
  for (Object mycolor : MyColor.values())

   System.out.println(mycolor);

  List<String> list = new ArrayList<String>();

  List<?> list2 = new ArrayList<String>();

  List<Integer> list3 = new ArrayList<Integer>();
  list3.add(0);
  for (Object integer : list3)
   System.out.println(integer.getClass().getName());

  // list.add(new Object());
  list2.add(null);

  for (Object o : list2) {
   System.out.println(o);
  }

 }

}

============ the file name: TestCaseDemo.java
package test;

import java.io.IOException;

import junit.framework.TestCase;
import junit.framework.TestResult;

public class TestCaseDemo extends TestCase {

 private int i;

 public TestCaseDemo() {
  System.out.println("this is the TestCaseDemo instance ... ");
 }

 public void testRAR() throws IOException {

  System.out.println("this is a test ... ");

  java.lang.Runtime rt = java.lang.Runtime.getRuntime();

  String compress = "D:/doc_c06_net.rar";// rar压缩文件

  String decompression = "D:/doc_redcome_com/";// 解压路径

  Process p = rt.exec("UNRAR.EXE x -o+ -p- " + compress + " "
    + decompression);

  StringBuffer sb = new StringBuffer();

  java.io.InputStream fis = p.getInputStream();

  int value = 0;

  while ((value = fis.read()) != -1) {

   sb.append((char) value);

  }
  fis.close();

  String result = new String(sb.toString().getBytes("ISO-8859-1"), "GBK");

  System.out.println(result);

 }

 public void testrar2() throws Exception {
                           // Str
 }

 @Override
 public TestResult run() {
  // TODO Auto-generated method stub

  System.out.println(">>>>>>>>>>>>...");
  return super.run();
 }

 @Override
 protected void setUp() throws Exception {
  // TODO Auto-generated method stub
  System.out.println(">>>>>>>>>>>>...");
  super.setUp();
 }

 @Override
 public int countTestCases() {
  // TODO Auto-generated method stub
  return super.countTestCases();
 }

 @Override
 protected TestResult createResult() {
  // TODO Auto-generated method stub
  return super.createResult();
 }

 @Override
 public String getName() {
  return super.getName();
 }

 @Override
 public void run(TestResult arg0) {
  // TODO Auto-generated method stub
  super.run(arg0);
 }

 @Override
 public void runBare() throws Throwable {
  // TODO Auto-generated method stub
  super.runBare();
 }

 @Override
 protected void runTest() throws Throwable {
  // TODO Auto-generated method stub
  super.runTest();
 }

 @Override
 public void setName(String arg0) {
  // TODO Auto-generated method stub
  super.setName(arg0);
 }

 @Override
 public String toString() {
  // TODO Auto-generated method stub
  return super.toString();
 }

 @Override
 protected Object clone() throws CloneNotSupportedException {
  // TODO Auto-generated method stub
  return super.clone();
 }

 @Override
 public boolean equals(Object obj) {
  // TODO Auto-generated method stub
  return super.equals(obj);
 }

 @Override
 protected void finalize() throws Throwable {
  // TODO Auto-generated method stub
  super.finalize();
 }

 @Override
 public int hashCode() {
  // TODO Auto-generated method stub
  return super.hashCode();
 }

 @Override
 protected void tearDown() throws Exception {
  // TODO Auto-generated method stub

  System.out.println(">>>>>>>>>>>>...");
  super.tearDown();
 }

}
============ the file name: TestTask.java
/*
 * Created on 2007-7-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package test;

import java.util.*;

/**
 * @author Carlos.Yang
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TestTask extends TimerTask{
 
 private static int i = 0;
 
 /* (non-Javadoc)
  * @see java.lang.Runnable#run()
  */
 public void run() {
  // TODO Auto-generated method stub
  System.out.println("this is a count: " + i++);
  
 }
 public static void main(String[] args) {
  System.out.println(">>>>>>>>>>>");
 }
}

============ the file name: TestTimer.java
/*
 * Created on 2007-7-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package test;

import java.awt.List;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.Timer;

import static java.lang.System.*;

;
/**
 * @author Carlos.Yang
 *
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class TestTimer {
 
 static void prtMax(int... nums) {

  System.out.println("the ... nums's type: " + nums.getClass().getName());
  if (nums.length == 0) {
   System.out.println(" no parameter ");
  } else {
   int maxNum = 0;
   for (int num : nums) {
    if (num > maxNum) {
     maxNum = num;
    }
   }
   System.out.println(maxNum);
  }
 }

 public static void main(String[] args) {

  String str = "dd";
  int k = 2;
  System.out.printf("str===%s k=%d", str, k);
  System.out.println();

  prtMax(1,99,4);

  ArrayList<String> list = new ArrayList<String>();
  list.add(new String("111"));
  list.add(new String("222"));
  list.add(new String("333"));

  for (String bean : list) {

   out.println("========" + bean);
  }

  // System.out.println("========start..");
  // Timer timer = new Timer();
  // TestTask tt = new TestTask();
  // timer.schedule(tt,1000,100);
  // System.out.println("..........");
  //  
  // List<Intger> list = new Vector<Intger>;
 }
}

============ the file name: ZipFloder.java
package test;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ZipFloder {

 private static int i;

 public static void main(String args[]) throws IOException {
  unpack();

 }

 private static void unpack() throws IOException {
  // TODO Auto-generated method stub
  String compress = "nutch-0.9.tar.gz";// zip压缩文件

  String decompression = "/f1";// 解压路径

  java.io.File dir = new java.io.File(decompression);

  java.util.zip.ZipFile zf = new java.util.zip.ZipFile(compress);

  java.util.Enumeration enumer = zf.entries();

  while (enumer.hasMoreElements()) {

   java.util.zip.ZipEntry ze = (java.util.zip.ZipEntry) enumer
     .nextElement();

   String zename = ze.getName();

   zename = new String(zename);// 文件名,不支持中文.

   System.out.println(zename);

   if (ze.isDirectory()) {
    java.io.File file = new java.io.File(dir.getAbsolutePath()
      + "/" + zename);

    file.mkdirs();
   } else {
    java.io.File file = new java.io.File(dir.getAbsolutePath()
      + "/" + zename).getParentFile();

    if (!file.exists()) {
     file.mkdirs();
    }
    byte zeby[] = new byte[(int) ze.getSize()];

    java.io.InputStream is = zf.getInputStream(ze);

    is.read(zeby);

    is.close();

    java.io.FileOutputStream fos = new java.io.FileOutputStream(dir
      .getAbsolutePath()
      + "/" + zename);

    fos.write(zeby);

    fos.close();
   }
  }
  zf.close();

 }

 private static void pack() throws IOException {
  // TODO Auto-generated method stub

  String compress = "/f2";// 要压缩的目录

  String decompression = "test.rar";// 压缩路径

  java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(
    new java.io.FileOutputStream(new java.io.File(decompression)));

  compress(zos, new File(compress));

  zos.close();
  System.out.println("the files count: " + i);
 }

 public static void compress(java.util.zip.ZipOutputStream zos,
   java.io.File file) throws java.io.IOException {
  if (file.isFile()) {
   byte by[] = new byte[(int) file.length()];

   java.io.FileInputStream is = new java.io.FileInputStream(file);

   is.read(by);

   is.close();

   java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(file
     .getPath());

   zos.putNextEntry(ze);

   zos.write(by);

   zos.closeEntry();
   System.out.println(file.getName());
  } else if (file.isDirectory()) {
   java.io.File files[] = file.listFiles();

   if (files != null)
    for (File f : files) {
     compress(zos, f);
     i++;
    }
  }

 }
}

============ the file name: ZipTest.java
package test;

import java.io.*;
import java.util.zip.*;

/**
 * @version Version 1.3
 */
public class ZipTest {
 public static void main(String[] args) {
  try {
   BufferedReader in = new BufferedReader(new InputStreamReader(
     new FileInputStream("fs/cb/Attribute.java"), "ISO8859_1"));
   FileOutputStream f = new FileOutputStream("ziptest" + ".zip");
   CheckedOutputStream ch = new CheckedOutputStream(f, new CRC32());
   ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(
     ch));

   int c;
   out.putNextEntry(new ZipEntry("fs/cb/Attribute.java"));
   while ((c = in.read()) != -1)
    out.write(c);
   in.close();
   out.close();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}
the threda's name: Thread-0java.lang.ThreadGroup[name=main,maxpri=10]   toString: Thread[Thread-0,5,main]
47

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值