java技術博客

          jsp博客
          數據加載中……

          本程序搜索文件中的字

               摘要: /** *//**  (C) 北大青鳥APTECH.  *   版權所有  */ /** *//**  * 本程序導入所需的類.  */ import java.io.File; import java.io.BufferedR...  閱讀全文

          posted @ 2008-10-30 09:12 郭興華 閱讀(72) | 評論 (0)編輯 收藏
          本程序搜索文件中的字

               摘要: /** *//**  (C) 北大青鳥APTECH.  *   版權所有  */ /** *//**  * 本程序導入所需的類.  */ import java.io.File; import java.io.BufferedR...  閱讀全文

          posted @ 2008-10-30 09:12 郭興華 閱讀(87) | 評論 (0)編輯 收藏
          本程序搜索文件中的字

               摘要: /** *//**  (C) 北大青鳥APTECH.  *   版權所有  */ /** *//**  * 本程序導入所需的類.  */ import java.io.File; import java.io.BufferedR...  閱讀全文

          posted @ 2008-10-30 09:12 郭興華 閱讀(103) | 評論 (0)編輯 收藏
          判斷一個一個路徑是否是目錄

          /**  
           *   (C) 北大青鳥APTECH.
           *   版權所有
           
          */


          /**
           * 本程序導入所需的類.
           
          */

          import java.io.File;

          /**
           * 本程序演示 File 類的使用.
           * 
          @version 1.0 2005 年 5 月 20 日
           * 
          @author Michael
           
          */


          class ListDirectory {

          /** 存儲要搜索的目錄名稱. */
              String directoryName;

          /** 聲明一個 File 對象. */
              File fileObj;

          /** 
           * 構造方法.
           * 
          @param name 是一個字符串
           
          */

              ListDirectory(String name) 
          {
                 directoryName 
          = name;
                 fileObj 
          = new File(name);
              }


          /** 
           * 顯示目錄和子目錄的方法.
           
          */

              
          void display() {
                 
          if (fileObj.isDirectory()) {
                    System.out.println(
          "目錄是 : " + directoryName);
                    String[] fileName 
          = fileObj.list();

                    
          for (int ctr = 0; ctr < fileName.length; ctr++{
                        File nextFileObj 
          = new File(directoryName + "/" + fileName[ctr]);

                        
          if (nextFileObj.isDirectory()) {
                           System.out.println(fileName[ctr] 
          + " 是一個目錄");
                        }
           else {
                           System.out.println(fileName[ctr] 
          + " 是一個文件");
                        }

                    }

                  }
           else {
                        System.out.println(directoryName 
          + " 不是一個有效目錄");
                  }

              }

          }


          /**
           * 本程序測試 ListDirectory 類.
           * 
          @version 1.0 2005 年 5 月 20 日
           * 
          @author Michael
           
          */


          class DirectoryTest {

          /** 
           * 構造方法. 
           
          */

              
          protected DirectoryTest() {
              }


          /**
           * 這是一個 main 方法.
           * 
          @param args 被傳遞至 main 方法
           
          */

              
          public static void main(String[] args) {
                  ListDirectory listObj 
          = new ListDirectory("java");
                  listObj.display();
              }

          }

          posted @ 2008-10-30 08:09 郭興華 閱讀(1087) | 評論 (0)編輯 收藏
          抽象類和方法的用法.

               摘要: /**//* 北大青鳥APTECH  * 版權所有  */ /** *//**  * 這個程序演示抽象類和方法的用法.  * @版本 1.0 2005 年 5 月 20 日  * @author M...  閱讀全文

          posted @ 2008-10-29 18:52 郭興華 閱讀(213) | 評論 (0)編輯 收藏
          java的多態

          /*  北大青鳥APTECH.
           *  版權所有
           
          */


          /**
           * 這個程序演示動態多態性的用法.
           * 
          @version 1.0 2005 年 5 月 20 日
           * 
          @author Michael
           
          */

          abstract class Shape {

              
          /** 存儲任何形狀的長. */
              
          protected double length;

              
          /** 存儲任何形狀的寬. */
              
          protected double width;

              
          /** 
               * 構造方法.
               * 
          @param num 傳遞至構造方法
               * 
          @param num1 傳遞至構造方法
               
          */

              Shape(
          final double num , final double num1) {

              
          /** 初始化變量. */
                  length 
          = num;
                  width 
          = num1;
              }


              
          /**
               * 抽象方法.
               * 
          @return double 值
               
          */

              
          abstract double area();
          }


          /**
           * 這個類重寫父類的方法.
           * 
          @version 1.0 2005 年 5 月 20 日
           * 
          @author Michael
           
          */


          class Square extends Shape {

              
          /** 構造方法.
               *
          @param num 傳遞至構造方法的參數
               *
          @param num1 傳遞至構造方法的參數
               
          */

              Square(
          final double num, final double num1) {
                  
          super(num, num1);
              }


              
          /**
               * 計算正方形的面積.
               * @return傳遞給構造方法的 length
               
          */


              
          double area() {
                  System.out.println(
          "正方形的面積為:" );
                  
          return length * width;
              }

          }


          /**
           * 這個類重寫父類的方法.
           * 
          @version 1.0 2005 年 5 月 20 日
           * 
          @author Michael
           
          */


          class Triangle extends Shape {

              
          /** 構造方法.
               *
          @param num 傳遞至構造方法的參數
               *
          @param num1 傳遞至構造方法的參數
               
          */

              Triangle(
          final double num, final double num1) {
                  
          super(num, num1);
              }


              
          /**
               * 計算三角形的面積.
               *
          @return double  傳遞給構造方法的length
               
          */


              
          double area() {
                  System.out.println(
          "三角形的面積為:" );
                  
          return (0.5 * length * width);
              }

          }


          /**
           * 這個類測試對象引用.
           * 
          @version 1.0 2005 年 5 月 20 日
           * 
          @author Michael
           
          */


          public class CalculateArea {

              
          /** 構造方法. */
              
          protected CalculateArea() {
              }


              
          /**
               * 這是 main 方法.
               * 
          @param arg 傳遞至 main 方法的參數
               
          */


              
          public static void main(final String[] arg) {
                  
          // 初始化變量
                  Shape fObj;
                  Square sqObj 
          = new Square(10 , 20);
                  Triangle trObj 
          = new Triangle(12 , 8);
                  fObj 
          = sqObj;
                  System.out.println(fObj.area());
                  fObj 
          = trObj;
                  System.out.println(fObj.area());
              }

          }

          posted @ 2008-10-29 07:39 郭興華 閱讀(136) | 評論 (0)編輯 收藏
          java數組的Copy

          /**
          * 測試數組元素拷貝
          */
          public class ArrayCopy
          {
          public static void main(String[] args)
          {
          ArrayCopy aCopy
          = new ArrayCopy();
          int[] a = {1, 2, 3, 4, 5};
          int[] b = {10,20,30,40,50};
          aCopy.copy(a, b);

          }

          public void copy(int[] from, int[] to)
          {
          System.out.println(
          "第一個數組中的元素");
          for (int i = 0; i < from.length; i++)
          {
          System.out.print(
          " " + from[i]);//打印出數組中的每一個元素
          }
          System.out.println(
          "\n");

          System.out.println(
          "第二個數組中的元素");
          for (int i = 0; i < to.length; i++)
          {
          System.out.print(
          " " + to[i]);//打印出數組中的每一個元素
          }

          System.out.println(
          "\n\n將第一個數組拷貝到第二個數組\n");
          System.arraycopy(from,
          2, to, 0, 3);

          System.out.println(
          "拷貝完成后第二個數組中的元素");
          for (int i = 0; i < to.length; i++)
          {
          System.out.print(
          " " + to[i]);//打印出數組中的每一個元素
          }
          }
          }

          輸出結果是3 4 5 40 50

          posted @ 2008-10-28 10:11 郭興華 閱讀(184) | 評論 (0)編輯 收藏
          JDBC連接SQLSERVER

               摘要: <%@page language="java" import="java.util.*,java.sql.*,Oper.*,voo.*" pageEncoding="GBK"%> <table border=1> <tr>     <th>編號</th>...  閱讀全文

          posted @ 2008-10-26 09:46 郭興華 閱讀(1824) | 評論 (0)編輯 收藏
          jsp讀取*.TXT

          package mypack;
          import java.io.*;

          public class ReadText{
              
          public String getShiGe(){
                  
          //File f=new File("guoxinghua.txt");
                  File f=new File(this.getClass().getResource("guoxinghua.txt").toURI());
                  
          try{
                      FileReader fr
          =new FileReader(f);
                      BufferedReader buff
          =new BufferedReader(fr);//BufferedReader用于讀取文本
                      String line="";
                      
          while((line=buff.readLine())!=null)
                      
          {
                          retstr
          +line+"<br>";
                          }

                          buff.close();
                          }

                      
          catch(Exception e)
                      
          {
                          e.printStackTrace();
                          
                          }

                          
                          
                          
          return retstr;
                          }

              }



          <%@page language="java" import="java.util.*,mypack" page Encoding="GBK"%>
          <%
          ReadText rt
          =new ReadText();
          %>
          <%=rt.getShiGe()%>

          posted @ 2008-10-26 07:20 郭興華 閱讀(767) | 評論 (1)編輯 收藏
          java1.5注解(二)


          import java.util.Date;
          import java.util.Map;
          import java.util.TreeMap;
          class  SuppressWarningsTest
          {
              
          public static void main(String[] args) 
              
          {
                  Map
          <String,Date> map=new TreeMap<String,Date>();
                  map.put(
          "hello",new Date());
                  System.out.println(map.get(
          "hello"));
              }

          }





          import java.util.Date;
          import java.util.Map;
          import java.util.TreeMap;
          class  SuppressWarningsTest2
          {
              
          public static void main(String[] args) 
              
          {
                  Map map
          =new TreeMap();
                  
          //Map<String,Date> map=new TreeMap<String,Date>();
                  map.put("hello",new Date());
                  System.out.println(map.get(
          "hello"));
              }

          }




          import java.util.Date;
          import java.util.Map;
          import java.util.TreeMap;
          class  SuppressWarningsTest3
          {
              @SuppressWarnings(
          "unchecked")
              
          public static void main(String[] args) 
              
          {
                  Map map
          =new TreeMap();
                  
          //Map<String,Date> map=new TreeMap<String,Date>();
                  map.put("hello",new Date());
                  System.out.println(map.get(
          "hello"));
              }

          }






          import java.util.Date;
          import java.util.Map;
          import java.util.TreeMap;
          class DeprecatedTest 
          {
              
          public void doSomething(){
              System.out.println(
          "guoxinghua");
              }

              
          public static void main(String[] args) 
              
          {
                  DeprecatedTest test
          =new DeprecatedTest();
                  test.doSomething();
                  
              }

          }


          class  SuppressWarningsTest2
          {
              
          public static void main(String[] args) 
              
          {
                  Map map
          =new TreeMap();
                  
          //Map<String,Date> map=new TreeMap<String,Date>();
                  map.put("hello",new Date());
                  System.out.println(map.get(
          "hello"));
              }

          }




          import java.util.Date;
          import java.util.Map;
          import java.util.TreeMap;
          class DeprecatedTest 
          {
              
          public void doSomething(){
              System.out.println(
          "guoxinghua");
              }

              
          public static void main(String[] args) 
              
          {
                  DeprecatedTest test
          =new DeprecatedTest();
                  test.doSomething();
                  
              }

          }


          class  SuppressWarningsTest2
          {
              @SuppressWarnings(
          {"unchecked","deprecation"})
              
          public static void main(String[] args) 
              
          {
                  Map map
          =new TreeMap();
                  
          //Map<String,Date> map=new TreeMap<String,Date>();
                  map.put("hello",new Date());
                  System.out.println(map.get(
          "hello"));
                  DeprecatedTest test
          =new DeprecatedTest();
                  test.doSomething();
              }

          }


          posted @ 2008-10-26 00:21 郭興華 閱讀(366) | 評論 (0)編輯 收藏
          僅列出標題
          共9頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 
          主站蜘蛛池模板: 福鼎市| 莒南县| 辰溪县| 平江县| 若羌县| 镇原县| 舞阳县| 托克逊县| 罗城| 田阳县| 大厂| 汤原县| 天门市| 邢台县| 繁昌县| 巨野县| 金沙县| 海原县| 健康| 通榆县| 云霄县| 安义县| 沛县| 晋中市| 大化| 宝丰县| 松江区| 大庆市| 读书| 汨罗市| 江源县| 太湖县| 六枝特区| 蓬溪县| 普兰店市| 门头沟区| 衡南县| 报价| 和顺县| 宣恩县| 通山县|