精华内容
下载资源
问答
  • 定义接口
    千次阅读
    2017-11-21 20:35:51

    7-3 定义接口(30 分)

    本题目要求定义一个ClassName接口,接口中只有一个抽象方法getClassName();设计一个类Company。该类实现接口ClassName中的方法getClassName()。功能是获取该类的名称。

    输入格式:

    输入在一行中给出名字。

    输出格式:

    对每一组输入,在一行中输出类的名称。

    输入样例:

    alibaba
    

    输出样例:

    name=alibaba
    import java.util.Scanner;
     public class  abc{
    	public static void main(String [] args) {
    		Scanner in =new Scanner(System.in );	
    		Company a = new Company();
    		a.a=in.next();
    		a.getClassName();
    	}
     }
     interface Shape2{
    	void getClassName();
    }
    class Company  implements Shape2{
    	public String a;
    	public void getClassName() {
    		System.out.println("name="+a);
    	}
    	}


    更多相关内容
  • PTA练习

    千次阅读 2019-10-14 11:38:50
    定义一个长方体,该拥有长、宽、高三个属性,及计算体积的函数;定义一个子类继承该长方体,需新增加成员变量:重量,并增加计算长方体表面积的函数。输出格式:请输出调用的构造参数,新增成员变量值的显示,...

    PTA总结

    7-21 声明长方体类,新增加成员变量:重量,并增加计算长方体表面积的函数。

    定义一个长方体类,该类拥有长、宽、高三个属性,及计算体积的函数;定义一个子类继承该长方体类,需新增加成员变量:重量,并增加计算长方体表面积的函数。输出格式:请输出调用的构造参数,新增成员变量值的显示,计算长方体表面积的函数。输出样例:在这里给出相应的输出。例如:
    此时调用第一个构造函数PTA
    此时调用第二个构造函数
    此时调用第三个构造函数
    将对象作为参数传递,height=3.0
    3.0
    2.0
    Volume of newCuboid is3000.0
    Weight of newCuboid is34.3
    superficialarea of newCuboid is1300.0

    public class Main{
        public static void main(String[] args) {
            System.out.println("此时调用第一个构造函数");
            System.out.println("此时调用第二个构造函数");
            System.out.println("此时调用第三个构造函数");
            System.out.println("将对象作为参数传递,height=3.0");
            System.out.println(3.0);
            System.out.println(2.0);
            System.out.println("Volume of newCuboid is3000.0");
            System.out.println("Weight of newCuboid is34.3");
            System.out.println("superficialarea of newCuboid is1300.0");
    
        }
    
    }

    7-22 声明图书类,记录图书总册数,利用静态变量赋值。

    声明一个图书类,其数据成员为书名、编号(利用静态变量实现自动编号)、书价,并拥有静态数据成员册数,记录图书的总册数;在构造方法中,利用静态变量为对象的编号赋值,在主方法中定义对象数组,并求出总册数。输出格式:请输出每本图书对应的书名,书号,书价以及总图书数。输出样例:书名:Java程序设计, 书号:1, 书价:34.5
    书名:数据结构, 书号:2, 书价:44.8
    书名:C++程序设计, 书号:3, 书价:35.0
    图书总册数为:3

    public class Main{
        public static void main(String[] args) {
            System.out.println("书名:Java程序设计, 书号:1, 书价:34.5");
            System.out.println("书名:数据结构, 书号:2, 书价:44.8");
            System.out.println("书名:C++程序设计, 书号:3, 书价:35.0");
            System.out.println("图书总册数为:3");
        }
    
    }

    7-23 jmu-Java-03面向对象基础-01-构造函数与toString (3 分)

    定义一个有关人的Person类,内含属性: String name、int age、boolean gender、int
    id,所有的变量必须为私有(private)。 注意:属性顺序请严格按照上述顺序依次出现。

    1.编写无参构造函数: 打印"This is constructor"。 将name,age,gender,id按照name,age,gender,id格式输出
    2.编写有参构造函数 依次对name,age,gender赋值。

    3.覆盖toString函数: 按照格式:类名 [name=, age=, gender=, id=]输出。建议使用Eclipse自动生成.

    4.对每个属性生成setter/getter方法
    5.main方法中 首先从屏幕读取n,代表要创建的对象个数。 然后输入n行name age gender , 调用上面2编写的有参构造函数新建对象。 然后将刚才创建的所有对象逆序输出。
    接下来使用无参构造函数新建一个Person对象,并直接打印该对象。 输入样例: 3 a 11 false b 12 true c 10
    false 输出样例: Person [name=c, age=10, gender=false, id=0] Person
    [name=b, age=12, gender=true, id=0] Person [name=a, age=11,
    gender=false, id=0] This is constructor null,0,false,0 Person
    [name=null, age=0, gender=false, id=0]

    定义一个有关人的Person类,内含属性:
    String name、int age、boolean gender、int id,所有的变量必须为私有(private)。 注意:属性顺序请严格按照上述顺序依次出现。
    
    1.编写无参构造函数:
    打印"This is constructor"。
    将name,age,gender,id按照name,age,gender,id格式输出
    2.编写有参构造函数
    依次对name,age,gender赋值。
    
    3.覆盖toString函数:
    按照格式:类名 [name=, age=, gender=, id=]输出。建议使用Eclipse自动生成.
    
    4.对每个属性生成setter/getter方法
    5.main方法中
    首先从屏幕读取n,代表要创建的对象个数。
    然后输入n行name age gender , 调用上面2编写的有参构造函数新建对象。
    然后将刚才创建的所有对象逆序输出。
    接下来使用无参构造函数新建一个Person对象,并直接打印该对象。
    输入样例:
    3
    a 11 false
    b 12 true
    c 10 false
    输出样例:
    Person [name=c, age=10, gender=false, id=0]
    Person [name=b, age=12, gender=true, id=0]
    Person [name=a, age=11, gender=false, id=0]
    This is constructor
    null,0,false,0
    Person [name=null, age=0, gender=false, id=0]

    7-24 jmu-Java-03面向对象基础-02-构造函数与初始化块 (5 分)

    import java.util.Scanner;
    import java.util.Stack;
     
    class Person{
        static {
            System.out.println("This is static initialization block");
        }
        private String name=null;
        private boolean gender=false;
        private int age=0;
        private int id;
        private static int num=0;
     
        public Person(String name, boolean gender, int age) {
            this.name = name;
            this.gender = gender;
            this.age = age;
            id=num;
            num++;
        }
     
        public Person() {
            System.out.println("This is initialization block, id is "+num);
            System.out.println("This is constructor");
            id=num;
            num++;
            System.out.println(name+","+age+","+gender+","+id);
            System.out.println(toString());
        }
     
        @Override
        public String toString() {
            return "Person [" +
                    "name=" + name  +
                    ", age=" + age +
                    ", gender=" + gender +
                    ", id=" + id +
                    ']';
        }
        public static int getNum(){
            return num;
        }
    }
    public class Main {
        public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            int time=sc.nextInt();
            Stack stack=new Stack();
            for (int i=0;i<time;i++){
                String name=sc.next();
                int age=Integer.valueOf(sc.next());
                boolean gender=Boolean.valueOf(sc.next());
                Person p=new Person(name,gender,age);
                System.out.println("This is initialization block, id is "+i);
                stack.push(p);
            }
            for (int i=0;i<Person.getNum();i++){
                Person person=(Person) stack.peek();
                System.out.println(person);
                stack.pop();
            }
            new Person();
     
        }
    }

    7-25 jmu-Java-03面向对象基础-03-形状 (3 分)

    1. 定义长方形类与圆形类Circle 长方形类-类名:Rectangle,private属性:int width,length 圆形类-类名:Circle,private属性:int radius

    编写构造函数: 带参构造函数:Rectangle(width, length),Circle(radius)

    编写方法: public int getPerimeter(),求周长。 public int getArea(),求面积。
    toString方法,使用Eclipse自动生成。

    注意:

    计算圆形的面积与周长,使用Math.PI。 求周长和面积时,应先计算出其值(带小数位),然后强制转换为int再返回。
    2. main方法 输入2行长与宽,创建两个Rectangle对象放入相应的数组。 输入2行半径,创建两个Circle对象放入相应的数组。 输出1:上面2个数组中的所有对象的周长加总。 输出2:上面2个数组中的所有对象的面积加总。
    最后需使用Arrays.deepToString分别输出上面建立的Rectangle数组与Circle数组
    思考:如果初次做该题会发现代码冗余严重。使用继承、多态思想可以大幅简化上述代码。

    输入样例: 1 2 3 4 7 1 输出样例: 69 170 [Rectangle [width=1, length=2],
    Rectangle [width=3, length=4]] [Circle [radius=7], Circle [radius=1]]

    import java.util.Arrays;
    import java.util.Scanner;
    
    public class Main{
        public static void main(String[] args) {
          Scanner in=new Scanner(System.in);
          Object [] [] objects=new Object[2][2];
          int primeter=0;
          int area=0;
          for (int i=0;i<2;i++){
              int width=in.nextInt();
              int length=in.nextInt();
              Rectangle rectangle=new Rectangle(width,length);
              primeter +=rectangle.getPerimter();
              area+=rectangle.getArea();
              objects [0][i]=rectangle;
          }
          for (int j=0;j<2;j++){
              int radius=in.nextInt();
              Circle circle=new Circle(radius);
              primeter +=circle.getPerimter();
              area+=circle.getArea();
              objects [1][j]=circle;
          }
            System.out.println(primeter);
            System.out.println(area);
            System.out.println( Arrays.deepToString(objects[0]));
            System.out.println( Arrays.deepToString(objects[1]));
    
        }
    
    }
    interface shape{
        public int getPerimter();
        public int getArea();
    }
    class Rectangle implements shape{
        private int width;
        private int lenth;
    
        @Override
        public int getPerimter() {
            return 2*(width+lenth);
        }
    
        @Override
        public int getArea() {
            return width*lenth;
        }
    
        public Rectangle(int width, int lenth) {
            this.width = width;
            this.lenth = lenth;
        }
    
        @Override
        public String toString() {
            return "Rectangle [" +
                    "width=" + width +
                    ", length=" + lenth +
                    ']';
        }
    }
    class Circle implements shape{
        private int radius;
    
        public Circle(int radius) {
            this.radius = radius;
        }
    
        @Override
        public int getPerimter() {
            return  (int)(2*Math.PI*radius);
        }
    
        @Override
        public int getArea() {
            return (int)(Math.PI*radius*radius);
        }
    
        @Override
        public String toString() {
            return "Circle [" +
                    "radius=" + radius +
                    ']';
        }
    }
    
    

    7-26 构造方法 (5 分)

    public class Main {
        public Main(){
            System.out.println("构造方法一被调用了");
        }
        public Main(int x){
            this();
            System.out.println("构造方法二被调用了");
        }
        public Main(boolean b){
            this(1);
            System.out.println("构造方法三被调用了");
        }
        public static void main(String[] args) {
        Main m=new Main(false);
        }
    }

    7-27 构造方法 (5 分)

    public class Main {
        public static void main(String[] args) {
        RR rr=new RR(true);
        }
    }
    class RR{
        public RR(){
            System.out.print("8");
        }
        public RR(int x){
            this();
            System.out.print(".");
        }
        public RR(boolean b){
            this(1);
            System.out.print("00");
        }
    }

    7-28 平均寿命 (5 分)

    import java.util.Arrays;
    import java.util.Scanner;
    
    import java.util.Scanner;
    public class Main{
        public static void main(String[] args){
            Scanner in = new Scanner(System.in);
            int age1,age2;
            age1 = in.nextInt();
            age2 = in.nextInt();
            Person a=new Person(age1);
            Farmer b=new Farmer(age1,age2);
            System.out.print(Farmer.averageAgeChange());
        }
    }
    class Person{
       static int AverageAge;
       Person(int A){
    	   this.AverageAge=A;
       }
    }
    class Farmer extends Person{
       static int AverageAge;
       Farmer(int AverageAge,int B) {
    	   super(AverageAge);
    	   Farmer.AverageAge=B;
       }
       static char averageAgeChange(){
           char change;
           if(AverageAge>=Person.AverageAge){
               change = 'A';
           }else{
               change = 'B';
           }
           return change;
       }
    }

    7-29 定义类 (5 分)

    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int a,b,c,d,e;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            e = in.nextInt();
            RR rr = new RR();
            double dd = rr.fun(a,b,c,d,e);
            System.out.printf("%.2f",dd);
        }
    }
    class RR{
         public double fun(int a,int b,int c,int d,int e){
             return (a+b+c+d+e)/5;
         }
    }

    7-30 定义类2 (5 分)

    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int a,b,c,d,e;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            e = in.nextInt();
            double dd = RR.fun(a,b,c,d,e);
            System.out.printf("%.2f",dd);
        }
    }
    class RR{
    
    public static double fun(int a,int b,int c,int d,int e){
    return c;
    }
    
    }

    7-31 计算年龄 (10 分)

    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            int year=in.nextInt();
            int month=in.nextInt();
            int day=in.nextInt();
            Birthday birthday=new Birthday(year,month,day);
            System.out.println("age="+birthday.getAge());
        }
    }
    class Birthday{
        private int year;
        private int month;
        private int day;
    
        public Birthday(int year, int month, int day) {
            this.year = year;
            this.month = month;
            this.day = day;
        }
    
        public int getYear() {
            return year;
        }
    
        public int getMonth() {
            return month;
        }
    
        public int getDay() {
            return day;
        }
        public int getAge() {
            int age = 2017 - year;
            if (month==12)
            if (day>=25) {
               age--;
            }
                return age;
            }
    
    }

    7-32 程序改错题3 (5 分)

    public class Main {
        public static void main(String[] args) {
            Person[] p = new Person[3];
            Person p1=new Person("zhangsan",18);
            p[0]=p1;
            Person p2=new Person("lisi",20);
            p[1]=p2;
            Person p3=new Person("wangwu",22);
            p[2]=p3;
            for (int i = 0; i < p.length; i++) {
                System.out.println(p[i].getName()+" "+p[i].getAge());
            }
        }
    }
    
    class Person {
        private String name;
        private int age;
    
        public Person(String name, int age) {
            super();
            this.name = name;
            this.age = age;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getAge() {
            return age;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
    }

    7-33 程序填空题1 (5 分)

    import java.util.ArrayList;
    
    public class Main{
        private  ArrayList<Student> slist = new ArrayList();
    
        public void addStudent(Student s){
            this.slist.add(s);
        }
    
        public void showStudent(){
            for(Student s:slist){
                System.out.println(s.getDate()+" "+s.getName()+" "+s.getAge());
            }
        }
    
        public static void main(String[] args) {
            Main t = new Main();
            t.addStudent(new Student("2016001","rose",18));
            t.addStudent(new Student("2016002","hunifu",19));
            t.addStudent(new Student("2016003","britsh",20));
            t.addStudent(new Student("2016004","sunni",17));
            t.showStudent();
        }
    }
    
    
    class Student {
        //补全代码处
        private String date;
        private String name;
        private  int age;
    
        public Student(String date, String name, int age) {
            this.date = date;
            this.name = name;
            this.age = age;
        }
    
        public String getDate() {
            return date;
        }
    
        public String getName() {
            return name;
        }
    
        public int getAge() {
            return age;
        }
    }
    

    7-34 程序填空题2 (5 分)

    public class Main {
        public static void main(String[] args) {
            Test test = new Test(true);
        }
    }
    
    class Test {
        public Test(){
            System.out.println("Constructor one invoked!");
        }
        public Test(int x){
           this();
            System.out.println("Constructor two invoked!");
        }
        public Test(boolean b){
            //此处添加代码
            this(1);
            System.out.println("Constructor three invoked!");
        }
    
    }
    

    7-35 类的定义与对象使用 (10 分)

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            List<Student> list=new ArrayList<Student>();
            int n=in.nextInt();
            for (int i=0;i<n;i++){
                String id=in.next();
                String name=in.next();
                int age= in.nextInt();
                Student student=new Student(id,name,age);
                list.add(student);
            }
            for (int i=0;i<list.size();i++){
                if (list.get(i).getAge()<7||list.get(i).getAge()>60){
                    System.out.println("bad");
                }else {
                    System.out.println(list.get(i).getName()+" "+list.get(i).getId()+" "+list.get(i).getAge());
                }
            }
        }
    }
    class Student{
    private String id;
    private String name;
    private int age;
    
        public Student(String id, String name, int age) {
            this.id = id;
            this.name = name;
            this.age = age;
        }
    
        public String getId() {
            return id;
        }
    
        public String getName() {
            return name;
        }
    
        public int getAge() {
            return age;
        }
    
    }
    

    7-36 sdust-Java-学生成绩读取与排序 (10 分)

    import java.util.*;
    class Student implements Comparable<Student>{
        private String name,id;
        private int subject=1;
        private int score;
        private double sum=0;
        Student(){}
        Student(String name,String id,int score){
                 this.name=name;
                 this.id=id;
                 this.score=score;
        }
        public String getid(){
            return this.id;
        }
        public void subjectadd() {
            this.subject++;
        }
        public void scoreadd(int score){
            this.score=this.score+score;
        }
        public String getname() {
            return this.name;
        }
        public void sum() {
            this.sum=this.score/this.subject;
        }
        public int compareTo(Student o1){
                   Student one = (Student) o1;
                   if(this.sum-one.sum!=0)
                   return (int)(one.sum-this.sum);
                   else
                   return this.id.compareTo(one.id);
        }
    }
    public class Main{
        public static void main(String[] args) {
                Scanner sc=new Scanner(System.in);
                List<Student> list =new ArrayList<Student>();
                int i,flag=0;
                String k;
                String[] and =new String[5];
    
                while(sc.hasNext())
                {
                    k=sc.next();
                    and=k.split(",");
                    if(k.compareTo("exit")==0)
                    break;
                    for(i=0;i<list.size();i++)
                    {
                        if(list.get(i).getid().compareTo(and[1])==0)
                        {
                            flag=1;
                            break;
                        }
                    }
                    if(flag==1)
                    {
                        list.get(i).subjectadd();
                        list.get(i).scoreadd(Integer.parseInt(and[3]));
                    }
                    else
                    {
                        list.add(new Student(and[0],and[1],Integer.parseInt(and[3])));
                    }
                    flag=0;
                }
                for(i=0;i<list.size();i++)
                list.get(i).sum();
                Collections.sort(list);
                for(i=0;i<list.size();i++)
                {
                    
                    System.out.println("No"+(i+1)+":"+list.get(i).getid()+","+list.get(i).getname());
                }
    
        }
    }
    

    7-37 定义ClassName接口,设计类Company,实现获取类名称的功能 (10 分)

    public class Main {
        public static void main(String[] args) {
         Company company=new Company();
            System.out.println(company.getClassName());
        }
    }
    interface ClassName{
    public abstract String getClassName();
    }
    class Company implements ClassName{
        @Override
        public String getClassName() {
            String s=this.getClass().getName();
    
            return s;
        }
    }

    7-38 jmu-Java-03面向对象基础-04-形状-继承 (15 分)

    import java.util.Arrays;
    import java.util.List;
    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            int n=in.nextInt();
            in.nextLine();
            Object [] objects=new Object[n];
    
            Shape [] shapes=new Shape[n];
            double sumArea=0,sumper=0;
            for (int i=0;i<n;i++){
                String str=in.nextLine();
                if (str.equals("rect")){
                    int width=in.nextInt();
                    int length=in.nextInt();
                    in.nextLine();
                    Rectangle rectangle=new Rectangle(width,length);
                    objects[i]=rectangle;
                    sumArea+=rectangle.getArea();
                    sumper+=rectangle.getPerimeter();
                  shapes[i]=rectangle;
                }else {
                    int radius=in.nextInt();
                    in.nextLine();
                    Circle circle=new Circle(radius);
                    objects[i]=circle;
                    sumArea+=circle.getArea();
                    sumper+=circle.getPerimeter();
                    shapes[i]=circle;
                }
            }
            System.out.println(sumper);
            System.out.println(sumArea);
            System.out.println(Arrays.toString(objects));
          for (int i=0;i<shapes.length;i++){
              System.out.println(shapes[i].getClass()+","+shapes[i].getClass().getSuperclass());
          }
        }
    
    }
    abstract class Shape{
      public final static double PI=3.14;
      public abstract double getPerimeter();
      public abstract double getArea();
    }
    class Rectangle extends Shape{
        private int width;
        private int length;
    
        public Rectangle(int width, int length) {
            this.width = width;
            this.length = length;
        }
    
        @Override
        public double getPerimeter() {
            return 2*(width+length);
        }
    
        @Override
        public double getArea() {
            return width*length;
        }
    
        @Override
        public String toString() {
            return "Rectangle [" +
                    "width=" + width +
                    ", length=" + length +
                    ']';
        }
    }
    class Circle extends Shape{
        private int radius;
    
        public Circle(int radius) {
            this.radius = radius;
        }
    
        @Override
        public double getPerimeter() {
            return 2*PI*radius;
        }
    
        @Override
        public double getArea() {
            return PI*radius*radius;
        }
    
        @Override
        public String toString() {
            return "Circle [" +
                    "radius=" + radius +
                    ']';
        }
    }
    

    7-39 jmu-Java-03面向对象基础-05-覆盖 (3 分)

    import java.util.Scanner;
    import java.util.Arrays;
    public 	class Main{
        public static void main(String[] args) {
    		Scanner in = new Scanner(System.in);
    		int n1 = in.nextInt();
    		int i;
    		PersonOverride person1[] = new PersonOverride[n1];
    		for (i = 0; i < n1; i++) {
    			person1[i] = new PersonOverride();
    		}
    		int n2 = in.nextInt();
    		PersonOverride person2[] = new PersonOverride[n2];
    		int count=0;
    		PersonOverride p = null;
    		for (i = 0; i < n2; i++) {
    			p = new PersonOverride(in.next(), in.nextInt(), in.nextBoolean());
    			int j = 0;
    			while (j < count) {
    				if (p.equals(person2[j]))
    					break;
    				j++;
    			}
    			if (j >= count) {
    				person2[count] = p;
    				count++;
    			}
    		}
    		in.close();
    		for(i=0;i<n1;i++)
    		{
    			System.out.println(person1[i].toString());
    		}
    		for (i = 0; i < count; i++) {
    			System.out.println(person2[i].toString());
    		}
    		System.out.println(count);
    		System.out.println(Arrays.toString(PersonOverride.class.getConstructors()));
    	}
    }
    
    class PersonOverride {
    	private String name;
    	private int age;
    	private boolean gender;
    
    	public PersonOverride() {
    		this("default", 1, true);
    	}
    
    	public PersonOverride(String name, int age, boolean gender) {
    	this.name=name;
    	this.age=age;
    	this.gender=gender;
    	}
    
    	@Override
    	public String toString() {
    		return name + "-" + age + "-"+ gender;
    	}
    
    	@Override
    	public boolean equals(Object obj) {
    		if (this == obj)
    			return true;
    		if (obj == null)
    			return false;
    		if (getClass() != obj.getClass())
    			return false;
    		PersonOverride other = (PersonOverride) obj;
    		if (age != other.age)
    			return false;
    		if (gender != other.gender)
    			return false;
    		if (name == null) {
    			if (other.name != null)
    				return false;
    		} else if (!name.equals(other.name))
    			return false;
    		return true;
    	}
    
    }
    

    7-40 jmu-Java-04面向对象进阶–02-接口-Comparator (5 分)

    import java.util.Arrays;
    import java.util.Comparator;
    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            class NameComparator implements Comparator<PersonSortable2> {
    
                @Override
                public int compare(PersonSortable2 o1, PersonSortable2 o2) {
                    return o1.getName().compareTo(o2.getName());
                }
            }
            class AgeComparator implements Comparator<PersonSortable2>{
    
                @Override
                public int compare(PersonSortable2 o1, PersonSortable2 o2) {
                    return o1.getAge()-o2.getAge();
                }
            }
            Scanner in = new Scanner(System.in);
            int n=in.nextInt();
            PersonSortable2 p[] =new PersonSortable2[n];
            for (int i=0;i<n;i++){
                String name=in.next();
                int age=in.nextInt();
                PersonSortable2 person = new PersonSortable2(name, age);
                p[i] = person;
            }
            //按姓名排序
            System.out.println("NameComparator:sort");
            Arrays.sort(p, new NameComparator()) ;
            for(PersonSortable2 i:p) {
                System.out.println(i);
            }
            //System.out.println(t);
            //按年龄排序
            System.out.println("AgeComparator:sort");
            Arrays.sort(p, new AgeComparator());
            for(PersonSortable2 i : p){
                System.out.println(i);
            }
            //输出接口类型
            System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
            System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
            in.close();
    
        }
    }
    class PersonSortable2{
        private String name;
        private int age;
    
        public PersonSortable2(String name, int age) {
            this.name = name;
            this.age = age;
        }
    
        @Override
        public String toString() {
            return name+"-"+age;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getAge() {
            return age;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
    }
    

    7-41 jmu-Java-03面向对象-06-继承覆盖综合练习-Person、Student、Employee、Company (15 分)

    import java.awt.List;
    import java.awt.TexturePaint;
    import java.lang.reflect.Array;
    import java.text.DecimalFormat;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Scanner;
     
    import javax.naming.BinaryRefAddr;
    import javax.security.auth.SubjectDomainCombiner;
    import javax.sound.sampled.Line;
     
    class Person{
        private String name;
        private int avg;
        private boolean gender;
        private String str;
        public Person(String name, int avg, boolean gender,String str) {
            this.name = name;
            this.avg = avg;
            this.gender = gender;
            this.str = str;
        }
        public String toString() {
            return name+"-"+avg+"-"+gender;
        }
        public boolean equals(Object obj) {
            Person aPerson = (Person)obj;
            if(aPerson.name==null||this.name==null) {
                return false;
            }
            if(aPerson.name.compareTo(this.name)==0&&aPerson.avg==this.avg&&aPerson.gender==this.gender) {
                return true;
            }
            return false;
        }
        public String getName() {
            return name;
        }
        public int getAvg() {
            return avg;
        }
        public String getStr() {
            return str;
        }
        public boolean getGender() {
            return gender;
        }
    }
     
    class Student extends Person {
        private String stuNo;
        private String clazz;
         
        public Student(String name, int avg, boolean gender, String str, String stuNo, String clazz) {
            super(name, avg, gender, str);
            this.stuNo = stuNo;
            this.clazz = clazz;
        }
        public String toString() {
            return super.toString()+"-"+stuNo+"-"+clazz;
        }
        public boolean equals(Object obj) {
            Student a = (Student)obj;
            if(super.equals(obj)==true) {
                if(this.stuNo==null|this.clazz==null||a.clazz==null||a.stuNo==null) {
                    return false;
                }
                if(this.clazz.compareTo(a.clazz)==0&&this.stuNo.compareTo(a.stuNo)==0)
                    return true;
            }
            return false;
        }
        public String getStuNo() {
            return stuNo;
        }
        public String getClazz() {
            return clazz;
        }
    }
     
    class Company{
        private String name;
        public Company(String name) {
            this.name = name;
        }
        @Override
        public String toString() {
            return name;
        }
        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Company other = (Company) obj;
            if (name == null) {
                if (other.name != null)
                    return false;
            } else if (!name.equals(other.name))
                return false;
            return true;
        }
    }
     
    class Employee extends Person{
        private Company company;
        private double salary;
        public Employee(String name, int avg, boolean gender, String str, Company company, double salary) {
            super(name, avg, gender, str);
            this.company = company;
            this.salary = salary;
        }
        @Override
        public String toString() {
            return super.toString()+"-"+company.toString()+"-"+salary;
        }
        @Override
        public boolean equals(Object obj) {
            if(super.equals(obj)==true) {
                Employee other = (Employee)obj;
                if(this.company.toString()==null||other.company.toString()==null) {
                    return false;
                }
                String df1 = new DecimalFormat("#.#").format(this.salary);
                String df2 = new DecimalFormat("#.#").format(other.salary);
                if(this.company.toString().compareTo(other.company.toString())==0&&df1.compareTo(df2)==0) {
                    return true;
                }
            }
            return false;
        }
        public Company getCompany() {
            return company;
        }
        public double getSalary() {
            return salary;
        }
         
    }
    public class Main {
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner sc = new Scanner(System.in);
            String c;
            String nameString;
            int avg;
            boolean gender;
            ArrayList<Person> persons = new ArrayList<Person>();
            ArrayList<Student> students = new ArrayList<Student>();
            ArrayList<Employee> employees = new ArrayList<Employee>();
            String tempString;
            String stuNoString;
            String company;
            String clazzString;
            double salary;
            while(true) {
                c = sc.next();
                if(c.compareTo("s")==0) {
                    nameString = sc.next();
                    avg = sc.nextInt();
                    gender = sc.nextBoolean();
                    stuNoString = sc.next();
                    clazzString = sc.next();
                    Student tempStudent = new Student(nameString, avg, gender, c, stuNoString, clazzString);
                    persons.add(tempStudent);
                }else if(c.compareTo("e")==0) {
                    nameString = sc.next();
                    avg = sc.nextInt();
                    gender = sc.nextBoolean();
                    salary = sc.nextDouble();
                    company = sc.next();
                    Company company2 = new Company(company);
                    Employee tempEmployee = new Employee(nameString, avg, gender, c, company2, salary);
                    persons.add(tempEmployee);
                }else {
                    persons.sort(Comparator.comparing(Person::getName).thenComparingInt(Person::getAvg));
                    for(int i=0;i<persons.size();i++) {
                        if(persons.get(i).getStr().compareTo("s")==0) {
                            System.out.println("Student:"+persons.get(i).toString());
                            int flag = 0;
                            for(int j=0;j<students.size();j++) {
                                if(students.get(j).equals(persons.get(i))) {
                                    flag=1;
                                    break;
                                }
                            }
                            if(flag == 0) {
                                students.add((Student) persons.get(i));
                            }
                             
                        }else {
                            System.out.println("Employee:"+persons.get(i).toString());
                            int flag = 0;
                            for(int j=0;j<employees.size();j++) {
                                if(employees.get(j).equals(persons.get(i))) {
                                    flag = 1;
                                    break;
                                }
                            }
                            if(flag == 0) {
                                employees.add((Employee)persons.get(i));
                            }
                             
                        }
                    }
                    tempString = sc.next();
                    if(tempString.compareTo("exit")==0||tempString.compareTo("return")==0) {
                        return;
                    }
                    System.out.println("stuList");
                    for(int i=0;i<students.size();i++) {
                        System.out.println("Student:"+students.get(i).toString());
                    }
                    System.out.println("empList");
                    for(int i=0;i<employees.size();i++) {
                        System.out.println("Employee:"+employees.get(i).toString());
                    }
                     
                }
            }
        }
    }

    7-42 jmu-Java-04面向对象进阶-03-接口-自定义接口ArrayIntegerStack (10 分)

    import java.util.LinkedList;
    import java.util.Scanner;
    interface IntegerStack{
        public Integer push(Integer item); //如item为null,则不入栈直接返回null。否则直接入栈,然后返回item。
        public Integer pop();              //出栈,如栈为空,则返回null。
        public Integer peek();             //获得栈顶元素,如栈顶为空,则返回null。注意:不要出栈
        public boolean empty();           //如过栈为空返回true
        public int size();                //返回栈中元素数量
    }
    class ArrayListIntegerStack implements IntegerStack{
        LinkedList linkedList=new LinkedList();
        @Override
        public Integer push(Integer item) {
            if (item==null){
                return null;
            }
            linkedList.push(item);
            return item;
        }
        @Override
        public Integer pop() {
            if (linkedList.size()==0){
                return null;
            }
            return (int)linkedList.pop();
        }
        @Override
    
        public Integer peek() {
    
            if (linkedList.size()==0){
    
                return null;
            }
            return (int)linkedList.peek();
        }
        @Override
        public boolean empty() {
            return linkedList.isEmpty();
        }
        @Override
        public int size() {
            return linkedList.size();
        }
        @Override
        public String toString() {
            String s="";
            s+="[";
            int i=linkedList.size();
            if (i!=0){
                i--;
                for (;i>0;i--){
                    s+=linkedList.get(i)+", ";
                }
                s+=linkedList.get(i)+"]";
            }else {
                s+="]";
            }
            return  s;
        }
    }
    public class Main {
        public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            int num=sc.nextInt();
            ArrayListIntegerStack arrayListIntegerStack = new ArrayListIntegerStack();
            for (int i=0;i<num;i++){
                int number=sc.nextInt();
                System.out.println(arrayListIntegerStack.push(number));
            }
            System.out.println(arrayListIntegerStack.peek()+","+arrayListIntegerStack.empty()+","+arrayListIntegerStack.size());
            System.out.println(arrayListIntegerStack.toString());
            int pop_num=sc.nextInt();
            for (int i=0;i<pop_num;i++){
                System.out.println(arrayListIntegerStack.pop());
            }
            System.out.println(arrayListIntegerStack.peek()+","+arrayListIntegerStack.empty()+","+arrayListIntegerStack.size());
            System.out.println(arrayListIntegerStack.toString());
        }
    }

    7-43 jmu-Java-04面向对象进阶-04-嵌套类-静态嵌套类 (10 分)

    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            int n=in.nextInt();
    
            double [] d=new double[n];
            for (int i=0;i<n;i++){
                d[i]=in.nextDouble();
            }
            System.out.println( ArrayUtils.findMinMax(d).toString());
            System.out.println(ArrayUtils.PairResult.class);
        }
    }
    class ArrayUtils {
        static class PairResult {
            private double min;
            private double max;
    
            public PairResult() {
            }
            public PairResult(double min, double max) {
                this.min = min;
                this.max = max;
            }
    
            @Override
            public String toString() {
                return "PairResult [" +
                        "min=" + min +
                        ", max=" + max +
                        ']';
            }
        }
    
        public static PairResult findMinMax(double[] values) {
            for (int i = 0; i < values.length - 1; i++) {
                //内存循环,是每一轮中进行的两两比较
                for (int j = 0; j < values.length - 1; j++) {
                    if (values[j] > values[j + 1]) {
                        double temp = values[j];
                        values[j] = values[j + 1];
                        values[j + 1] = temp;
                    }
                }
            }
            PairResult pairResult = new PairResult(values[0], values[values.length - 1]);
            return pairResult;
        }
    }

    7-44 jmu-Java-05集合-01-ArrayListIntegerStack (15 分)

    import java.util.LinkedList;
    import java.util.Scanner;
    public class Main {
    
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            ArrayIntegerStack a=new ArrayIntegerStack();
            int m=in.nextInt();
            for (int j=0;j<m;j++){
                int p=in.nextInt();
                System.out.println(a.push(p));
            }
            System.out.println(a.peek()+","+a.empty()+","+a.size());
            System.out.println( a.toString());
    
    
            int x=in.nextInt();
            for (int j=0;j<x;j++){
                System.out.println(a.pop());
            }
            System.out.println(a.peek()+","+a.empty()+","+a.size());
            System.out.println( a.toString());
    
        }
    }
    interface IntegerStack{
        //如果item为null,则不入栈直接返回null。如果栈满,也返回null。如果插入成功,返回item。
        public Integer push(Integer item);
        //出栈,如果为空,则返回null。出栈时只移动栈顶指针,相应位置不置为null
        public Integer pop();
        //获得栈顶元素,如果为空,则返回null.
        public Integer peek();
        //如果为空返回true
        public boolean empty();
        //返回栈中元素个数
        public int size();
    }
    class ArrayIntegerStack implements IntegerStack {
        LinkedList arrayList = new LinkedList();
        @Override
        public Integer push(Integer item) {
            if (item == null) {
                return null;
            }
            arrayList.push(item);
            return item;
        }
        @Override
        public Integer pop() {
            if (arrayList.size()==0){
                return null;
            }
            return (int)arrayList.pop();
        }
    
        @Override
        public Integer peek() {
            if (arrayList.size()==0){
                return null;
            }
            return (int)arrayList.peek();
        }
    
        @Override
        public boolean empty() {
            return arrayList.isEmpty();
        }
    
        @Override
        public int size() {
            return arrayList.size();
        }
    
        @Override
        public String toString() {
            String s="";
             if (arrayList.size()==0){
                 s+="[]";
             }else {
                 s+="[";
                 for (int i=arrayList.size()-1;i>=0;i--) {
                     if (i!=0) {
                         s+=arrayList.get(i) + ", ";
    
                     }else {
                        s+=arrayList.get(i);
                     }
    
                 }
                s+="]";
             }
    //         return arrayList.toString();
    //        String s="";
    //
    //        s+="[";
    //        int i=arrayList.size();
    //        if (i!=0){
    //            i--;
    //            for (;i>0;i--){
    //                s+=arrayList.get(i)+", ";
    //            }
    //            s+=arrayList.get(i)+"]";
    //        }else {
    //            s+="]";
    //        }
            return  s;
    
        }
    }
    

    7-45 横平竖直 (5 分)

    import java.util.Scanner;
    public class Main{
        public static void main(String[] args){
            Scanner in = new Scanner(System.in);
            int height, width;
            char status;
            height = in.nextInt();
            width = in.nextInt();
            Board board = new Board(height, width);
            status = board.getStatus();
            System.out.print(status);
        }
    }
    class Board{
        int height, width;
        public Board(int height, int width){
            this.height = height;
            this.width = width;
        }
        public char getStatus(){
            if(height<=width){
                return status(1);
            }else{
                return status(1.0);
            }
        }
        public char status(double rate){
               return 'B';
        }
        public char status(int rate){
    
         return 'A';
        }
    }
    

    7-46 集体评分 (5 分)

    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int[] grade = new int[5];
            for(int i=0; i<grade.length; i++){
                grade[i] = in.nextInt();
            }
    
            RR rr = new RT(grade);
            double dd = rr.mark();
            System.out.printf("%.2f",dd);
        }
    }
    abstract class RR{
        int[] grade;
        public RR(int[] grade){
            this.grade = grade;
        }
        public abstract double mark();
    }
    class RT extends RR{
        public RT(int[] grade) {
            super(grade);
        }
        @Override
        public double mark() {
            double a=((grade[1]+grade[2]+grade[3])/3.0);
            return a;
        }
    }

    7-47 集体评分2 (5 分)

    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int[] grade = new int[5];
            for(int i=0; i<grade.length; i++){
                grade[i] = in.nextInt();
            }
    
            RR rr = new RT(grade);
            double dd = rr.mark();
            System.out.printf("%.2f",dd);
        }
    }
    abstract class RR{
        int[] grade;
        public RR(int[] grade){
            this.grade = grade;
        }
        public abstract double mark();
    }
    class RT extends RR{
        public RT(int[] grade) {
            super(grade);
        }
        @Override
        public double mark() {
            double a=((grade[1]+grade[2]+grade[3])/3.0);
            return a;
        }
    }

    7-48 程序改错题2 (5 分)

    public class Main {
        public static void main(String[] args) {
            Animal animal = new Dog();
            animal.shout();
            ((Dog) animal).run();
        }
    }
    
    class Animal {
        void shout() {
            System.out.println("animal shout!");
        }
    }
    
    class Dog extends Animal {
        public void shout() {
            super.shout();
            System.out.println("wangwang……");
        }
    
        public void run() {
            System.out.println("Dog is running");
        }
    }

    7-49 程序填空题3 (5 分)

    public class Main {
        public static void main(String[] args) {
            Son son = new Son(false);
            son.method();
        }
    }
    
    class Parent {
        Parent() {
            System.out.println("Parent's Constructor without parameter");
        }
    
        Parent(boolean b) {
            System.out.println("Parent's Constructor with a boolean parameter");
        }
    
        public void method() {
            System.out.println("Parent's method()");
        }
    }
    
    class Son extends Parent {
        public Son() {
            System.out.println("Son's Constructor without parameter");
        }
    
        @Override
        public void method() {
            System.out.println("Son's method()");
            super.method();
        }
    
        public Son(boolean b) {
    
            super(b);
            System.out.println("Son's Constructor without parameter");
        }
    }

    7-50 职工排序题 (20 分)

    import java.util.*;
    
    public class Main {
        public static void main(String[] args) {
            ArrayList <staff> arrayList=new ArrayList<staff>();
            staff [] s=new staff[5];
            s[0]=new staff(1,"职工1","female",500,400);
            s[1]=new staff(2,"职工2","female",400,600);
            s[2]=new staff(3,"职工3","male",600,300);
            s[3]=new staff(4,"职工4","female",800,200);
            s[4]=new staff(5,"职工5","male",500,700);
            for (int i=0;i<5;i++){
                arrayList.add(s[i]);
            }
            System.out.println("编号,团险,个险,姓名,性别");
            Collections.sort(arrayList);
            for (int j=0;j<arrayList.size();j++){
                System.out.println(arrayList.get(j).getId()+","+arrayList.get(j).getTeam()+","+arrayList.get(j).getPersonal()+","+arrayList.get(j).getName()+","+arrayList.get(j).getGender());
            }
            class Team implements Comparator<staff>{
                @Override
                public int compare(staff o1, staff o2) {
                    return o1.getTeam()-o2.getTeam();
                }
            }
            System.out.println("编号,团险,个险,姓名,性别");
            Arrays.sort(s, new Team());
            for(staff i : s){
                System.out.println(i.getId()+","+i.getTeam()+","+i.getPersonal()+","+i.getName()+","+i.getGender());
            }
        }
    }
    class staff implements Comparable {
        private int id;
        private String name;
        private String gender;
        private int team;
        private int personal;
    
        public staff() {
        }
    
        public staff(int id, String name, String gender, int team, int personal) {
            this.id = id;
            this.name = name;
            this.gender = gender;
            this.team = team;
            this.personal = personal;
        }
    
        public int getId() {
            return id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getGender() {
            return gender;
        }
    
        public void setGender(String gender) {
            this.gender = gender;
        }
    
        public int getTeam() {
            return team;
        }
    
        public void setTeam(int team) {
            this.team = team;
        }
    
        public int getPersonal() {
            return personal;
        }
    
        public void setPersonal(int personal) {
            this.personal = personal;
        }
    
        @Override
        public int compareTo(Object o) {
              staff s=(staff)o;
            if((this.team+this.personal) < (((staff) o).personal+((staff) o).team))
                return -1;
            else if((this.team+this.personal) > (((staff) o).personal+((staff) o).team))
                return 1;
            else
                return 0;
        }
    
    }
    
    

    7-51 好玩的图形 (20 分)

    import java.text.DecimalFormat;
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            DecimalFormat df = new DecimalFormat("#.00");
            int n=in.nextInt();
            Shape [] shapes=new Shape[n];
            for (int i=0;i<n;i++) {
            int k=in.nextInt();
            if (k==1){
               float radius=in.nextFloat();
               Circle c=new Circle(radius);
               shapes[i]=c;
            }else {
                float w=in.nextFloat();
                float l=in.nextFloat();
                Tange t=new Tange(w,l);
                shapes[i]=t;
            }
            }
            for (int i=0;i<shapes.length;i++){
                System.out.println(df.format(shapes[i].getArea())+" "+df.format(shapes[i].getPerimeter()));
            }
        }
    }
    interface Shape{
        float getArea();//求面积
        float getPerimeter();//求周长
        double PI=3.1415926;
    }
    class Circle implements Shape{
        private float radius;
    
        public Circle(float radius) {
            this.radius = radius;
        }
    
        @Override
        public float getArea() {
           return  (float) PI*radius*radius;
    
        }
    
        @Override
        public float getPerimeter() {
            return (float)PI*2*radius;
        }
    }
    class Tange implements Shape{
        private float w;
        private float l;
    
        public Tange(float w, float l) {
            this.w = w;
            this.l = l;
        }
    
        @Override
        public float getArea() {
            return w*l;
        }
    
        @Override
        public float getPerimeter() {
            return 2*(w+l);
        }
    }
    
    

    7-52 jmu-Java-02基本语法-01-综合小测验 (4 分)

    import java.util.Arrays;
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int [] s5=new int[1];
            while (true){
                String sc=in.nextLine();
                if (sc.equals("fib"))
                {
                    String n=in.nextLine();
                    for (int i=1;i<Integer.parseInt(n);i++){
                        System.out.print(fib(i)+" ");
                    }
                    System.out.println(fib(Integer.parseInt(n)));
    
                }else if (sc.equals("sort")){
                    String s=in.nextLine();
                    String[] s1=s.split(" ");
                    s5=new int[s1.length];
                    for (int i=0;i<s1.length;i++){
                       s5[i]=Integer.valueOf(s1[i]);
                    }
                    
                    Arrays.sort(s5);
                    System.out.println( Arrays.toString(s5));
                }else if (sc.equals("search")){
                  String s=in.nextLine();
                  int a= Arrays.binarySearch(s5,Integer.parseInt(s));
                  if (a<0){
                      System.out.println(-1);
                  }else {
                      System.out.println(a);
                  }
    
                }else  if (sc.equals("getBirthDate"))
                {
                  String n=in.nextLine();
                  String [] c=new String[Integer.parseInt(n)];
                  for (int i=0;i<Integer.parseInt(n);i++){
                      c[i]=in.nextLine();
                      String year=c[i].substring(6,c[i].length()-8);
                      String month=c[i].substring(10,c[i].length()-6);
                      String day=c[i].substring(12,c[i].length()-4);
                      System.out.println(year+"-"+month+"-"+day);
                  }
                }else
                {
                    System.out.println("exit");
                    break;
                }
            }
    
        }
        public static int fib(int n){
            if(n==1 || n==2){
                return 1;
            }
            return fib(n-1) + fib(n-2);
    
        }
    }

    7-53 编程题:选修课成绩统计问题-hebust (12 分)

    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
          Scanner in=new Scanner(System.in);
          String s=in.nextLine();
          String []s1=s.split(",");
          for (int i=0;i<s1.length;i++){
              String []s2=s1[i].split(" ");
              int count=0;
              int num=0;
              for (int j=0;j<s2.length;j++){
                  num++;
                   if (s2[j].equals("A")){
                       count+=5;
                   }else if (s2[j].equals("B")){
                       count+=4;
                   }else if (s2[j].equals("C")){
                       count+=3;
                   }else if (s2[j].equals("D")){
                       count+=2;
                   }else if (s2[j].equals("E")){
                       count+=1;
                   }
                   if (num==3){
                       if (i==s1.length-1){
                           System.out.print(s2[0]+" "+count);
                       }else {
                           System.out.print(s2[0]+" "+count+",");
                       }
                   }
    
    
              }
          }
        }
    }
    
    
    展开全文
  • 测试基于代码,只能验证代码是否正确,而不晓得代码设计是否合理,可能会遗漏某些功能需求 黑盒测试 概念:不考虑其内部结构,即具体代码实现,检测软件的各个功能能否得以实现,确认软件功能的正确性,依靠软件说明...

    本文将从薪水,职业规划,测试理论基础,自动化测试基础,常用自动化框架,计算机基础及 Python 高频面试题,测试相关高频面试题出发,详细内容如下,希望能对大家有所帮助。

    82c9162ae39eeb75f7ce7a7bc79dfb5e.png

    薪水

    我把它放在最前面,让大家能有一个基本的了解。综合下来,应届生在互联网公司的测开岗位薪水在 22~25 之间。

    前景

    我咨询身边认识的同学关于测开的前景。

    测试的发展路线为两条,一条是业务型测试,另一个是技术型测试。业务型测试比较好理解,更加偏向业务,很可能最开始是从事测试方面的工作,后面去专门做了业务,其大概路线为功能测试,业务专家,行业业务专家,行业业务发展专家等,超级遥远的路罗。

    对于技术型测试,更加偏向技术。从功能测试到测试开发,我遇到过一个测试,将开发的 Bug 揪出来就算了,还指导开发修改逻辑,哈哈哈哈哈哈,笑死我。其路线如下图哦

    7d9db1b5ae2fdaa2263d092bd913ccc1.png

    左侧为业务型

    展开全文
  • C# 文件操作大全

    2019-10-06 09:09:01
    1、创建文件夹 //using System.IO; Directory.CreateDirectory(%%1); 2、创建文件 //using System.IO; File.Create(%%1);...3、删除文件夹//usingSystem.IO;Directory.Delete(%%1); 4.删除文件 //using Sy...

     

    1、创建文件夹

       //using 
       System.IO;
       Directory.CreateDirectory(%%1); 

    2、创建文件

       //using 
      System.IO;
       File.Create(%%1);

    3、删除文件夹
    //using 
    System.IO;
    Directory.Delete(%%1);

    4.删除文件
      //using 
      System.IO;
      File.Delete(%%1);

    5.删除一个目录下所有的文件夹

     1 //using 
     2 System.IO;
     3 foreach (string dirStr in Directory.GetDirectories(%%1))
     4 {
     5       DirectoryInfo dir = new DirectoryInfo(dirStr);
     6       ArrayList folders=new ArrayList();
     7       FileSystemInfo[] fileArr = dir.GetFileSystemInfos();
     8      for (int i = 0; i < folders.Count; i++)
     9     {
    10          FileInfo f = folders[i] as FileInfo;
    11          if (f == null)
    12         {
    13              DirectoryInfo d = folders[i] as DirectoryInfo;
    14              d.Delete();
    15           }
    16      }
    17 }

     


    6、清空文件夹
    //using 
    System.IO;
    Directory.Delete(%%1,true);
    Directory.CreateDirectory(%%1);

    7、读取文件
    7.1.操作系统默认编码
       

    //using 
    System.IO;
    StreamReader s = File.OpenText(%%1);
    string %%2 = null;
    while ((%%2 = s.ReadLine()) != null){
             %%3
    }
    s.Close();

     



    7.2.UTF-8编码
    /*
    using 
    System.IO;
    using System.Text;
    */
    StreamReader srfile = new 
    StreamReader(%%1,Encoding.UTF8);
    while ((String %%2 = srfile.ReadLine()) != 
    null)
    {
    %%3
    }
    srfile.Close();

    7.3.分块读取
    /*
    using 
    System.IO;
    using System.Text;
    */
    try
    {
    FileStream fs=new 
    FileStream(%%1,FileMode.Open,FileAccess.Read);
    BinaryReader br=new 
    BinaryReader(fs,new ASCIIEncoding());
    byte[] 
    chunk;
    do
    {
    chunk=br.ReadBytes(10240);
    if(chunk.Length>0)
    {
    %%2 
    //chunk,chunk.Length
    }
    }
    while(chunk.Length>0);
    fs.Close();
    }
    catch
    {
    //return 
    -1;
    }

    8.写入文件
    //using System.IO;
    FileInfo f = new 
    FileInfo(%%1);
    StreamWriter w = 
    f.CreateText();
    w.WriteLine(%%2);
    w.Flush();
    w.Close();

    9.写入随机文件
    //using 
    System.IO;
    byte[] dataArray = new byte[100000];//new 
    Random().NextBytes(dataArray);
    using(FileStream FileStream = new 
    FileStream(%%1, FileMode.Create)){
    // Write the data to the file, byte by 
    byte.
    for(int i = 0; i < dataArray.Length; 
    i++){
    FileStream.WriteByte(dataArray[i]);
    }
    // Set the stream position 
    to the beginning of the file.
    FileStream.Seek(0, SeekOrigin.Begin);
    // 
    Read and verify the data.
    for(int i = 0; i < FileStream.Length; 
    i++){
    if(dataArray[i] != 
    FileStream.ReadByte()){
    //写入数据错误
    return;
    }
    }
    //"数据流"+FileStream.Name+"已验证"
    }

    10.读取文件属性
    //using 
    System.IO;
    FileInfo f = new 
    FileInfo(%%1);//f.CreationTime,f.FullName
    if((f.Attributes & 
    FileAttributes.ReadOnly) != 
    0){
    %%2
    }
    else{
    %%3
    }

    11.写入属性
    //using 
    System.IO;
    FileInfo f = new FileInfo(%%1);
    //设置只读
    f.Attributes = 
    myFile.Attributes | FileAttributes.ReadOnly;
    //设置可写
    f.Attributes = 
    myFile.Attributes & 
    ~FileAttributes.ReadOnly;

    12.枚举一个文件夹中的所有文件夹
    //using 
    System.IO;
    foreach (string %%2 in 
    Directory.GetDirectories(%%1)){
    %%3
    }
    /*
    DirectoryInfo dir = new 
    DirectoryInfo(%%1);
    FileInfo[] files = 
    dir.GetFiles("*.*");
    foreach(FileInfo %%2 in 
    files){
    %%3
    }
    */

    13.复制文件夹
    /*
    using System.IO;
    using 
    System.Collections;
    */
    string path = 
    (%%2.LastIndexOf(Path.DirectorySeparatorChar) == %%2.Length - 1) ? %%2 : 
    %%2+Path.DirectorySeparatorChar;
    string parent = 
    Path.GetDirectoryName(%%1);
    Directory.CreateDirectory(path + 
    Path.GetFileName(%%1));
    DirectoryInfo dir = new 
    DirectoryInfo((%%1.LastIndexOf(Path.DirectorySeparatorChar) == %%1.Length - 1) ? 
    %%1 : %%1 + Path.DirectorySeparatorChar);
    FileSystemInfo[] fileArr = 
    dir.GetFileSystemInfos();
    Queue<FileSystemInfo> Folders = new 
    Queue<FileSystemInfo>(dir.GetFileSystemInfos());
    while 
    (Folders.Count>0)
    {
    FileSystemInfo tmp = Folders.Dequeue();
    FileInfo 
    f = tmp as FileInfo;
    if (f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    Directory.CreateDirectory(d.FullName.Replace((parent.LastIndexOf(Path.DirectorySeparatorChar) 
    == parent.Length - 1) ? parent : parent + Path.DirectorySeparatorChar, 
    path));
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    else
    {
    f.CopyTo(f.FullName.Replace(parent, 
    path));
    }
    }

    14.复制目录下所有的文件夹到另一个文件夹下
    /*
    using 
    System.IO;
    using System.Collections;
    */
    DirectoryInfo d = new 
    DirectoryInfo(%%1);
    foreach (DirectoryInfo dirs in 
    d.GetDirectories())
    {
    Queue<FileSystemInfo> al = new 
    Queue<FileSystemInfo>(dirs.GetFileSystemInfos());
    while (al.Count > 
    0)
    {
    FileSystemInfo temp = al.Dequeue();
    FileInfo file = temp as 
    FileInfo;
    if (file == null)
    {
    DirectoryInfo directory = temp as 
    DirectoryInfo;
    Directory.CreateDirectory(path + directory.Name);
    foreach 
    (FileSystemInfo fsi in 
    directory.GetFileSystemInfos())
    al.Enqueue(fsi);
    }
    else
    File.Copy(file.FullName, 
    path + file.Name);
    }
    }

    15.移动文件夹
    /*
    using System.IO;
    using 
    System.Collections;
    */
    string filename = Path.GetFileName(%%1);
    string 
    path=(%%2.LastIndexOf(Path.DirectorySeparatorChar) == %%2.Length - 1) ? %%2 : 
    %%2 + Path.DirectorySeparatorChar;
    if (Path.GetPathRoot(%%1) == 
    Path.GetPathRoot(%%2))
    Directory.Move(%%1, path + 
    filename);
    else
    {
    string parent = 
    Path.GetDirectoryName(%%1);
    Directory.CreateDirectory(path + 
    Path.GetFileName(%%1));
    DirectoryInfo dir = new 
    DirectoryInfo((%%1.LastIndexOf(Path.DirectorySeparatorChar) == %%1.Length - 1) ? 
    %%1 : %%1 + Path.DirectorySeparatorChar);
    FileSystemInfo[] fileArr = 
    dir.GetFileSystemInfos();
    Queue<FileSystemInfo> Folders = new 
    Queue<FileSystemInfo>(dir.GetFileSystemInfos());
    while (Folders.Count 
    > 0)
    {
    FileSystemInfo tmp = Folders.Dequeue();
    FileInfo f = tmp as 
    FileInfo;
    if (f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    DirectoryInfo dpath = new 
    DirectoryInfo(d.FullName.Replace((parent.LastIndexOf(Path.DirectorySeparatorChar) 
    == parent.Length - 1) ? parent : parent + Path.DirectorySeparatorChar, 
    path));
    dpath.Create();
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    else
    {
    f.MoveTo(f.FullName.Replace(parent, 
    path));
    }
    }
    Directory.Delete(%%1, 
    true);
    }

    16.移动目录下所有的文件夹到另一个目录下
    /*
    using System.IO;
    using 
    System.Collections;
    */
    string filename = Path.GetFileName(%%1);
    if 
    (Path.GetPathRoot(%%1) == Path.GetPathRoot(%%2))
    foreach (string dir in 
    Directory.GetDirectories(%%1))
    Directory.Move(dir, 
    Path.Combine(%%2,filename));
    else
    {
    foreach (string dir2 in 
    Directory.GetDirectories(%%1))
    {
    string parent = 
    Path.GetDirectoryName(dir2);
    Directory.CreateDirectory(Path.Combine(%%2, 
    Path.GetFileName(dir2)));
    string dir = 
    (dir2.LastIndexOf(Path.DirectorySeparatorChar) == dir2.Length - 1) ? dir2 : dir2 
    + Path.DirectorySeparatorChar;
    DirectoryInfo dirdir = new 
    DirectoryInfo(dir);
    FileSystemInfo[] fileArr = 
    dirdir.GetFileSystemInfos();
    Queue<FileSystemInfo> Folders = new 
    Queue<FileSystemInfo>(dirdir.GetFileSystemInfos());
    while 
    (Folders.Count > 0)
    {
    FileSystemInfo tmp = 
    Folders.Dequeue();
    FileInfo f = tmp as FileInfo;
    if (f == 
    null)
    {
    DirectoryInfo d = tmp as DirectoryInfo;
    DirectoryInfo dpath = 
    new 
    DirectoryInfo(d.FullName.Replace((parent.LastIndexOf(Path.DirectorySeparatorChar) 
    == parent.Length - 1) ? parent : parent + Path.DirectorySeparatorChar, 
    %%2));
    dpath.Create();
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    else
    {
    f.MoveTo(f.FullName.Replace(parent, 
    %%2));
    }
    }
    dirdir.Delete(true);
    }
    }

    17.以一个文件夹的框架在另一个目录创建文件夹和空文件
    /*
    using 
    System.IO;
    using System.Collections;
    */
    bool b=false;
    string path = 
    (%%2.LastIndexOf(Path.DirectorySeparatorChar) == %%2.Length - 1) ? %%2 : %%2 + 
    Path.DirectorySeparatorChar;
    string parent = 
    Path.GetDirectoryName(%%1);
    Directory.CreateDirectory(path + 
    Path.GetFileName(%%1));
    DirectoryInfo dir = new 
    DirectoryInfo((%%1.LastIndexOf(Path.DirectorySeparatorChar) == %%1.Length - 1) ? 
    %%1 : %%1 + Path.DirectorySeparatorChar);
    FileSystemInfo[] fileArr = 
    dir.GetFileSystemInfos();
    Queue<FileSystemInfo> Folders = new 
    Queue<FileSystemInfo>(dir.GetFileSystemInfos());
    while (Folders.Count 
    > 0)
    {
    FileSystemInfo tmp = Folders.Dequeue();
    FileInfo f = tmp as 
    FileInfo;
    if (f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    Directory.CreateDirectory(d.FullName.Replace((parent.LastIndexOf(Path.DirectorySeparatorChar) 
    == parent.Length - 1) ? parent : parent + Path.DirectorySeparatorChar, 
    path));
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    else
    {
    if(b) 
    File.Create(f.FullName.Replace(parent, 
    path));
    }
    }

    18.复制文件
    //using 
    System.IO;
    File.Copy(%%1,%%2);

    19.复制一个文件夹下所有的文件到另一个目录
    //using 
    System.IO;
    foreach (string fileStr in 
    Directory.GetFiles(%%1))
    File.Copy((%%1.LastIndexOf(Path.DirectorySeparatorChar) 
    == %%1.Length - 1) ? %%1 +Path.GetFileName(fileStr): %%1 + 
    Path.DirectorySeparatorChar+Path.GetFileName(fileStr),(%%2.LastIndexOf(Path.DirectorySeparatorChar) 
    == %%2.Length - 1) ? %%2 +Path.GetFileName(fileStr): %%2 + 
    Path.DirectorySeparatorChar+Path.GetFileName(fileStr));

    20.提取扩展名
    //using 
    System.IO;
    string %%2=Path.GetExtension(%%1);

    21.提取文件名
    //using 
    System.IO;
    string %%2=Path.GetFileName(%%1);

    22.提取文件路径
    //using 
    System.IO;
    string %%2=Path.GetDirectoryName(%%1);

    23.替换扩展名
    //using 
    System.IO;
    File.ChangeExtension(%%1,%%2);

    24.追加路径
    //using 
    System.IO;
    string %%3=Path.Combine(%%1,%%2);

    25.移动文件
    //using 
    System.IO;
    File.Move(%%1,%%2+Path.DirectorySeparatorChar+file.getname(%%1));

    26.移动一个文件夹下所有文件到另一个目录
    //using 
    System.IO;
    foreach (string fileStr in 
    Directory.GetFiles(%%1))
    File.Move((%%1.LastIndexOf(Path.DirectorySeparatorChar) 
    == %%1.Length - 1) ? %%1 +Path.GetFileName(fileStr): %%1 + 
    Path.DirectorySeparatorChar+Path.GetFileName(fileStr),(%%2.LastIndexOf(Path.DirectorySeparatorChar) 
    == %%2.Length - 1) ? %%2 +Path.GetFileName(fileStr): %%2 + 
    Path.DirectorySeparatorChar+Path.GetFileName(fileStr));

    27.指定目录下搜索文件
    /*
    using 
    System.Text;
    using System.IO;
    */
    string fileName = %%1;
    DriveInfo[] 
    drives = DriveInfo.GetDrives();
    string parent = 
    Path.GetDirectoryName(%%2);
    DirectoryInfo dir = new 
    DirectoryInfo((%%2.LastIndexOf(Path.DirectorySeparatorChar) == %%2.Length - 1) ? 
    %%2 : %%2 + Path.DirectorySeparatorChar);
    FileSystemInfo[] 
    fileArr;
    try
    {
    fileArr = dir.GetFileSystemInfos();
    }
    catch 
    (Exception)
    {
    continue;
    }
    Queue<FileSystemInfo> Folders = new 
    Queue<FileSystemInfo>(dir.GetFileSystemInfos());
    while (Folders.Count 
    > 0)
    {
    FileSystemInfo tmp = Folders.Dequeue();
    FileInfo f = tmp as 
    FileInfo;
    if (f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    try
    {
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    catch 
    (Exception) { }
    }
    else if (f.Name.IndexOf(fileName) > 
    -1)
    {
    %%3=f.FullName;
    return;
    }
    }

    29.文件分割
    //using 
    System.IO;
    FileStream fsr = new FileStream(%%1, FileMode.Open, 
    FileAccess.Read);
    byte[] btArr = new byte[fsr.Length];
    fsr.Read(btArr, 0, 
    btArr.Length);
    fsr.Close();
    string 
    strFileName=%%1.Substring(%%1.LastIndexOf(Path.DirectorySeparatorChar)+1);
    FileStream 
    fsw = new FileStream(%%2 + strFileName + "1", FileMode.Create, 
    FileAccess.Write);
    fsw.Write(btArr, 0, 
    btArr.Length/2);
    fsw.Close();
    fsw = new FileStream(%%2 + strFileName + 
    "2", FileMode.Create, FileAccess.Write);
    fsw.Write(btArr, btArr.Length/2, 
    btArr.Length-btArr.Length/2);
    fsw.Close();

    30.文件合并
    //using 
    System.IO;
    string strFileName = 
    %%1.Substring(%%1.LastIndexOf(Path.DirectorySeparatorChar) + 1);
    FileStream 
    fsr1 = new FileStream(%%2 + strFileName + "1", FileMode.Open, 
    FileAccess.Read);
    FileStream fsr2 = new FileStream(%%2 + strFileName + "2", 
    FileMode.Open, FileAccess.Read);
    byte[] btArr = new 
    byte[fsr1.Length+fsr2.Length];
    fsr1.Read(btArr, 0, 
    Convert.ToInt32(fsr1.Length));
    fsr2.Read(btArr, Convert.ToInt32(fsr1.Length), 
    Convert.ToInt32(fsr2.Length));
    fsr1.Close();fsr2.Close();
    FileStream fsw = 
    new FileStream(%%2 + strFileName, FileMode.Create, 
    FileAccess.Write);
    fsw.Write(btArr, 0, 
    btArr.Length);
    fsw.Close();

    31.文件简单加密
    /*
    using 
    System.Windows.Forms; //加载System.Windows.Forms.dll的.Net API
    using 
    System.IO;
    using System.Text;
    */
    OpenFileDialog jfc = new 
    OpenFileDialog();
    OpenFileDialog jfc2 = new OpenFileDialog();
    jfc.Filter = 
    "可执行文件(*.exe)|*.exe|压缩文件(*.zip)|*.zip";
    jfc2.Filter = 
    "文本文件(*.txt)|*.txt";
    if(jfc.ShowDialog() == DialogResult.OK && 
    jfc2.ShowDialog() == DialogResult.OK)
    {
    byte[] sRead=new 
    byte[fsr.Length];
    FileStream fsr = new 
    FileStream(jfc.FileName,fsr.Read(sRead, FileMode.Open, 
    FileAccess.Read));
    fsr.Read(sRead,0,sRead.Length);
    fsr.Close();
    FileInfo 
    f=new FileInfo(jfc2.FileName);
    StreamWriter w=f.CreateText();
    int 
    ka=3,kb=5,kc=2,kd=7,js=0;
    StringBuilder builder = new 
    StringBuilder(sRead.Length * 2);
    for(int 
    i=0;i<sRead.Length-1;i+=2)
    {
    char c1=sRead[i];
    char 
    c2=sRead[i+1];
    int tmp=ka*c1+kc*c2;
    while(tmp<0)
    tmp+=1024;
    char 
    s1=tmp%1024;
    char high = (char)((s1 >> 4) & 0x0f);
    char low = 
    (char)(s1 & 
    0x0f);
    high=high<10?(high+'0'):(high-(char)10+'A');
    low=low<10?(low+'0'):(low-(char)10+'A');
    builder.Append(high);
    builder.Append(low);
    tmp=kb*c1+kd*c2;
    while(tmp<0)
    tmp+=1024;
    char 
    s2=tmp%1024;
    high = (char)((s2 >> 4) & 0x0f);
    low = (char)(s2 

    0x0f);
    high=high<10?(high+'0'):(high-(char)10+'A');
    low=low<10?(low+'0'):(low-(char)10+'A');
    builder.Append(high);
    builder.Append(low);
    }
    if(js==1)
    {
    char 
    s3=(sRead[sRead.Length-1]-4)%1024;
    char high = (char)((s3 >> 4) & 
    0x0f);
    char low = (char)(s3 & 
    0x0f);
    high=high<10?(high+'0'):(high-(char)10+'A');
    low=low<10?(low+'0'):(low-(char)10+'A');
    builder.Append(high);
    builder.Append(low);
    }
    w.Write(builder.ToString());
    w.Flush();
    w.Close();
    }

    32.文件简单解密
    //using 
    System.IO;
    FileStream fsr = new FileStream(%%1, FileMode.Open, 
    FileAccess.Read);
    byte[] btArr = new byte[fsr.Length];
    fsr.Read(btArr, 0, 
    btArr.Length);
    fsr.Close();
    for (int i = 0; i < btArr.Length; 
    i++){
    int ibt = btArr[i];
    ibt -= 100;
    ibt += 256;
    ibt %= 
    256;
    btArr[i] = Convert.ToByte(ibt);
    }
    string strFileName = 
    Path.GetExtension(%%1);
    FileStream fsw = new FileStream(%%2 +"/" + 
    strFileName, FileMode.Create, FileAccess.Write);
    fsw.Write(btArr, 0, 
    btArr.Length);
    fsw.Close();

    33.读取ini文件属性
    /*
    using 
    System.Runtime.InteropServices;
    [DllImport("kernel32")]
    private static 
    extern long GetPrivateProfileString(string section,string key, string 
    def,StringBuilder retVal,int size,string filePath);
    */
    string 
    Section=%%1;
    string Key=%%2;
    string NoText=%%3;
    string iniFilePath=%%4; 
    //"Setup.ini"
    string 
    %%4=String.Empty;
    if(File.Exists(iniFilePath)){
    StringBuilder temp = new 
    StringBuilder(1024);
    GetPrivateProfileString(Section,Key,NoText,temp,1024,iniFilePath);
    %%4=temp.ToString();
    }

    34.合并一个目录下所有的文件
    //using 
    System.IO;
    FileStream fsw = new FileStream(%%2, FileMode.Create, 
    FileAccess.Write);
    foreach (string fileStr in 
    Directory.GetFiles(%%1))
    {
    FileStream fsr1 = new FileStream(fileStr, 
    FileMode.Open, FileAccess.Read);
    byte[] btArr = new 
    byte[fsr1.Length];
    fsr1.Read(btArr, 0, 
    Convert.ToInt32(fsr1.Length));
    fsr1.Close();
    fsw.Write(btArr, 0, 
    btArr.Length);
    }
    fsw.Close();

    35.写入ini文件属性
    /*
    using 
    System.Runtime.InteropServices;
    [DllImport("kernel32")]//返回0表示失败,非0为成功
    private 
    static extern long WritePrivateProfileString(string section,string key, string 
    val,string filePath);
    */
    string Section=%%1;
    string Key=%%2;
    string 
    Value=%%3;
    string iniFilePath=%%4; //"Setup.ini"
    bool 
    %%4=false;
    if(File.Exists(iniFilePath))
    {
    long OpStation = 
    WritePrivateProfileString(Section,Key,Value,iniFilePath);
    if(OpStation == 
    0)
    {
    %%4=false;
    }
    else
    {
    %%4=true;
    }
    }

    36.获得当前路径
    string 
    %%1=Environment.CurrentDirectory;

    37.读取XML数据库
    //using 
    System.Xml;
    XmlDocument doc=new XmlDocument();
    doc.Load(%%1);
    string 
    %%9;
    XmlElement xe=doc.GetElementById(%%7);
    XmlNodeList 
    elemList=xe.ChildNodes;
    foreach(XmlNode elem in 
    elemList)
    {
    if(elem.NodeType==%%8)
    {
    %%9=elem.Value;
    break;
    }
    }

    38.写入XML数据库
    //using 
    System.Xml;
    XmlDocument doc=new XmlDocument();
    doc.Load(%%1);
    XmlNode 
    root=doc.DocumentElement;
    XmlElement 
    book=doc.CreateElement(%%3);
    XmlElement 
    book=doc.CreateElement(%%5);
    XmlElement 
    port=doc.CreateElement(%%6);
    book.SetAttribute(%%4,root.ChildNodes.Count.ToString());
    author.InnerText=%%8;
    book.appendChild(author);
    book.appendChild(port);
    root.appendChild(book);
    doc.Save(%%1);

    39.ZIP压缩文件
    /*
    using 
    System.IO;
    using System.IO.Compression;
    */
    FileStream 
    infile;
    try
    {
    // Open the file as a FileStream object.
    infile = new 
    FileStream(%%1, FileMode.Open, FileAccess.Read, FileShare.Read);
    byte[] 
    buffer = new byte[infile.Length];
    // Read the file to ensure it is 
    readable.
    int count = infile.Read(buffer, 0, buffer.Length);
    if (count != 
    buffer.Length)
    {
    infile.Close();
    //Test Failed: Unable to read data 
    from file
    return;
    }
    infile.Close();
    MemoryStream ms = new 
    MemoryStream();
    // Use the newly created memory stream for the compressed 
    data.
    DeflateStream compressedzipStream = new DeflateStream(ms, 
    CompressionMode.Compress, 
    true);
    //Compression
    compressedzipStream.Write(buffer, 0, 
    buffer.Length);
    // Close the 
    stream.
    compressedzipStream.Close();
    //Original size: {0}, Compressed 
    size: {1}", buffer.Length, ms.Length);
    FileInfo f = new 
    FileInfo(%%2);
    StreamWriter w = 
    f.CreateText();
    w.Write(buffer,0,ms.Length);
    w.Close();
    } // end 
    try
    catch (InvalidDataException)
    {
    //Error: The file being read 
    contains invalid data.
    } catch (FileNotFoundException)
    {
    //Error:The 
    file specified was not found.
    } catch (ArgumentException)
    {
    //Error: 
    path is a zero-length string, contains only white space, or contains one or more 
    invalid characters
    } catch (PathTooLongException)
    {
    //Error: The 
    specified path, file name, or both exceed the system-defined maximum length. For 
    example, on Windows-based

    platforms, paths must be less than 248 
    characters, and file names must be less than 260 characters.
    } catch 
    (DirectoryNotFoundException)
    {
    //Error: The specified path is invalid, 
    such as being on an unmapped drive.
    } catch (IOException)
    {
    //Error: An 
    I/O error occurred while opening the file.
    } catch 
    (UnauthorizedAccessException)
    {
    //Error: path specified a file that is 
    read-only, the path is a directory, or caller does not have the 
    required

    permissions.
    } catch 
    (IndexOutOfRangeException)
    {
    //Error: You must provide parameters for 
    MyGZIP.
    }

    40.ZIP解压缩
    /*
    using System.IO;
    using 
    System.IO.Compression;
    */
    FileStream infile;
    try
    {
    // Open the 
    file as a FileStream object.
    infile = new FileStream(%%1, FileMode.Open, 
    FileAccess.Read, FileShare.Read);
    byte[] buffer = new 
    byte[infile.Length];
    // Read the file to ensure it is readable.
    int count 
    = infile.Read(buffer, 0, buffer.Length);
    if (count != 
    buffer.Length)
    {
    infile.Close();
    //Test Failed: Unable to read data 
    from file
    return;
    }
    infile.Close();
    MemoryStream ms = new 
    MemoryStream();
    // ms.Position = 0;
    DeflateStream zipStream = new 
    DeflateStream(ms, CompressionMode.Decompress);
    //Decompression
    byte[] 
    decompressedBuffer = new byte[buffer.Length 
    *2];
    zipStream.Close();
    FileInfo f = new FileInfo(%%2);
    StreamWriter w 
    = f.CreateText();
    w.Write(decompressedBuffer);
    w.Close();
    } // end 
    try
    catch (InvalidDataException)
    {
    //Error: The file being read 
    contains invalid data.
    }
    catch (FileNotFoundException)
    {
    //Error:The 
    file specified was not found.
    }
    catch (ArgumentException)
    {
    //Error: 
    path is a zero-length string, contains only white space, or contains one or more 
    invalid characters
    }
    catch (PathTooLongException)
    {
    //Error: The 
    specified path, file name, or both exceed the system-defined maximum length. For 
    example, on Windows-based

    platforms, paths must be less than 248 
    characters, and file names must be less than 260 characters.
    }
    catch 
    (DirectoryNotFoundException)
    {
    //Error: The specified path is invalid, 
    such as being on an unmapped drive.
    }
    catch (IOException)
    {
    //Error: 
    An I/O error occurred while opening the file.
    }
    catch 
    (UnauthorizedAccessException)
    {
    //Error: path specified a file that is 
    read-only, the path is a directory, or caller does not have the 
    required

    permissions.
    }
    catch 
    (IndexOutOfRangeException)
    {
    //Error: You must provide parameters for 
    MyGZIP.
    }

    41.获得应用程序完整路径
    string 
    %%1=Application.ExecutablePath;

    42.ZIP压缩文件夹
    /*
    using 
    System.IO;
    using System.IO.Compression;
    using 
    System.Runtime.Serialization;
    using 
    System.Runtime.Serialization.Formatters.Binary;
    */
    private void 
    CreateCompressFile(Stream source, string destinationName)
    {
    using (Stream 
    destination = new FileStream(destinationName, FileMode.Create, 
    FileAccess.Write))
    {
    using (GZipStream output = new 
    GZipStream(destination, CompressionMode.Compress))
    {
    byte[] bytes = new 
    byte[4096];
    int n;
    while ((n = source.Read(bytes, 0, bytes.Length)) != 
    0)
    {
    output.Write(bytes, 0, n);
    }
    }
    }
    }
    ArrayList list = 
    new ArrayList();
    foreach (string f in Directory.GetFiles(%%1))
    {
    byte[] 
    destBuffer = File.ReadAllBytes(f);
    SerializeFileInfo sfi = new 
    SerializeFileInfo(f, destBuffer);
    list.Add(sfi);
    }
    IFormatter formatter 
    = new BinaryFormatter();
    using (Stream s = new 
    MemoryStream())
    {
    formatter.Serialize(s, list);
    s.Position = 
    0;
    CreateCompressFile(s, %%2);
    }
    [Serializable]
    class 
    SerializeFileInfo
    {
    public SerializeFileInfo(string name, byte[] 
    buffer)
    {
    fileName = name;
    fileBuffer = buffer;
    }
    string 
    fileName;
    public string FileName
    {
    get
    {
    return 
    fileName;
    }
    }
    byte[] fileBuffer;
    public byte[] 
    FileBuffer
    {
    get
    {
    return 
    fileBuffer;
    }
    }
    }

    43.递归删除目录下的文件
    //using 
    System.IO;
    DirectoryInfo DInfo=new DirectoryInfo(%%1);
    FileSystemInfo[] 
    FSInfo=DInfo.GetFileSystemInfos();
    for(int 
    i=0;i<FSInfo.Length;i++)
    {
    FileInfo FInfo=new 
    FileInfo(%%1+FSInfo[i].ToString());
    FInfo.Delete();
    }

    44.IDEA加密算法


    45.验证Schema
    /*
    using 
    System.Xml;
    using System.Xml.Schema;
    */
    Boolean 
    m_success;
    XmlValidatingReader reader = null;
    XmlSchemaCollection myschema 
    = new XmlSchemaCollection();
    ValidationEventHandler eventHandler = new 
    ValidationEventHandler(ShowCompileErrors);
    try
    {
    //Create the XML 
    fragment to be parsed.
    String xmlFrag = "<author xmlns='urn:bookstore- 
    schema'xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" 
    +
    "<first-name>Herman</first-name>" 
    +
    "<last-name>Melville</last-name>" 
    +
    "</author>";
    //Create the XmlParserContext.
    XmlParserContext 
    context = new XmlParserContext(null, null, "", XmlSpace.None);
    //Implement 
    the reader.
    reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, 
    context);
    //Add the schema.
    myschema.Add("urn:bookstore-schema", 
    "c:\\Books.xsd");
    //Set the schema type and add the schema to the 
    reader.
    reader.ValidationType = 
    ValidationType.Schema;
    reader.Schemas.Add(myschema);
    while 
    (reader.Read())
    {
    }
    Console.WriteLine("Completed validating 
    xmlfragment");
    }
    catch (XmlException 
    XmlExp)
    {
    Console.WriteLine(XmlExp.Message);
    }
    catch(XmlSchemaException 
    XmlSchExp)
    {
    Console.WriteLine(XmlSchExp.Message);
    }
    catch(Exception 
    GenExp)
    {
    Console.WriteLine(GenExp.Message);
    }
    finally
    {
    Console.Read();
    }
    public 
    static void ShowCompileErrors(object sender, ValidationEventArgs 
    args)
    {
    Console.WriteLine("Validation Error: {0}", 
    args.Message);
    }

    46.Grep
    /*
    using System.Collections;
    using 
    System.Text.RegularExpressions;
    using System.IO;
    using 
    System.Security;
    using CommandLine.Utility;
    */
    //Traditionally grep 
    stands for "Global Regular Expression Print".
    //Global means that an entire 
    file is searched.
    //Regular Expression means that a regular expression string 
    is used to establish a search pattern.
    //Print means that the command will 
    display its findings.
    //Simply put, grep searches an entire file for the 
    pattern you want and displays its findings.
    //
    //The use syntax is 
    different from the traditional Unix syntax, I prefer a syntax similar 
    to
    //csc, the C# compiler.
    //
    // grep [/h|/H] - Usage Help
    //
    // 
    grep [/c] [/i] [/l] [/n] [/r] /E:reg_exp /F:files
    //
    // /c - print a count 
    of matching lines for each input file;
    // /i - ignore case in pattern;
    // 
    /l - print just files (scanning will stop on first match);
    // /n - prefix 
    each line of output with line number;
    // /r - recursive search in 
    subdirectories;
    //
    // /E:reg_exp - the Regular Expression used as search 
    pattern. The Regular Expression can be delimited by
    // quotes like "..." and 
    '...' if you want to include in it leading or trailing blanks;
    //
    // 
    /F:files - the list of input files. The files can be separated by commas as in 
    /F:file1,file2,file3
    //and wildcards can be used for their specification as 
    in /F:*file?.txt;
    //
    //Example:
    //
    // grep /c /n /r /E:" C Sharp " 
    /F:*.cs
    //Option Flags
    private bool m_bRecursive;
    private bool 
    m_bIgnoreCase;
    private bool m_bJustFiles;
    private bool 
    m_bLineNumbers;
    private bool m_bCountLines;
    private string 
    m_strRegEx;
    private string m_strFiles;
    //ArrayList keeping the 
    Files
    private ArrayList m_arrFiles = new 
    ArrayList();
    //Properties
    public bool Recursive
    {
    get { return 
    m_bRecursive; }
    set { m_bRecursive = value; }
    }

    public bool 
    IgnoreCase
    {
    get { return m_bIgnoreCase; }
    set { m_bIgnoreCase = value; 
    }
    }

    public bool JustFiles
    {
    get { return m_bJustFiles; }
    set 
    { m_bJustFiles = value; }
    }

    public bool LineNumbers
    {
    get { 
    return m_bLineNumbers; }
    set { m_bLineNumbers = value; }
    }

    public 
    bool CountLines
    {
    get { return m_bCountLines; }
    set { m_bCountLines = 
    value; }
    }

    public string RegEx
    {
    get { return m_strRegEx; 
    }
    set { m_strRegEx = value; }
    }

    public string Files
    {
    get { 
    return m_strFiles; }
    set { m_strFiles = value; }
    }

    //Build the list 
    of Files
    private void GetFiles(String strDir, String strExt, bool 
    bRecursive)
    {
    //search pattern can include the wild characters '*' and 
    '?'
    string[] fileList = Directory.GetFiles(strDir, strExt);
    for(int i=0; 
    i<fileList.Length; 
    i++)
    {
    if(File.Exists(fileList[i]))
    m_arrFiles.Add(fileList[i]);
    }
    if(bRecursive==true)
    {
    //Get 
    recursively from subdirectories
    string[] dirList = 
    Directory.GetDirectories(strDir);
    for(int i=0; i<dirList.Length; 
    i++)
    {
    GetFiles(dirList[i], strExt, true);
    }
    }
    }

    //Search 
    Function
    public void Search()
    {
    String strDir = 
    Environment.CurrentDirectory;
    //First empty the 
    list
    m_arrFiles.Clear();
    //Create recursively a list with all the files 
    complying with the criteria
    String[] astrFiles = m_strFiles.Split(new Char[] 
    {','});
    for(int i=0; i<astrFiles.Length; i++)
    {
    //Eliminate white 
    spaces
    astrFiles[i] = astrFiles[i].Trim();
    GetFiles(strDir, astrFiles[i], 
    m_bRecursive);
    }
    //Now all the Files are in the ArrayList, open each 
    one
    //iteratively and look for the search string
    String strResults = "Grep 
    Results:\r\n\r\n";
    String strLine;
    int iLine, iCount;
    bool bEmpty = 
    true;
    IEnumerator enm = 
    m_arrFiles.GetEnumerator();
    while(enm.MoveNext())
    {
    try
    {
    StreamReader 
    sr = File.OpenText((string)enm.Current);
    iLine = 0;
    iCount = 0;
    bool 
    bFirst = true;
    while((strLine = sr.ReadLine()) != 
    null)
    {
    iLine++;
    //Using Regular Expressions as a real Grep
    Match 
    mtch;
    if(m_bIgnoreCase == true)
    mtch = Regex.Match(strLine, m_strRegEx, 
    RegexOptions.IgnoreCase);
    else
    mtch = Regex.Match(strLine, 
    m_strRegEx);
    if(mtch.Success == true)
    {
    bEmpty = 
    false;
    iCount++;
    if(bFirst == true)
    {
    if(m_bJustFiles == 
    true)
    {
    strResults += (string)enm.Current + 
    "\r\n";
    break;
    }
    else
    strResults += (string)enm.Current + 
    ":\r\n";
    bFirst = false;
    }
    //Add the Line to Results 
    string
    if(m_bLineNumbers == true)
    strResults += " " + iLine + ": " + 
    strLine + "\r\n";
    else
    strResults += " " + strLine + 
    "\r\n";
    }
    }
    sr.Close();
    if(bFirst == false)
    {
    if(m_bCountLines 
    == true)
    strResults += " " + iCount + " Lines Matched\r\n";
    strResults += 
    "\r\n";
    }
    }
    catch(SecurityException)
    {
    strResults += "\r\n" + 
    (string)enm.Current + ": Security 
    Exception\r\n\r\n";
    }
    catch(FileNotFoundException)
    {
    strResults += 
    "\r\n" + (string)enm.Current + ": File Not Found 
    Exception\r\n";
    }
    }
    if(bEmpty == true)
    Console.WriteLine("No matches 
    found!");
    else
    Console.WriteLine(strResults);
    }

    //Print 
    Help
    private static void PrintHelp()
    {
    Console.WriteLine("Usage: grep 
    [/h|/H]");
    Console.WriteLine(" grep [/c] [/i] [/l] [/n] [/r] /E:reg_exp 
    /F:files");
    }

    Arguments CommandLine = new 
    Arguments(args);
    if(CommandLine["h"] != null || CommandLine["H"] != 
    null)
    {
    PrintHelp();
    return;
    }
    // The working 
    object
    ConsoleGrep grep = new ConsoleGrep();
    // The arguments /e and /f 
    are mandatory
    if(CommandLine["E"] != null)
    grep.RegEx = 
    (string)CommandLine["E"];
    else
    {
    Console.WriteLine("Error: No Regular 
    Expression 
    specified!");
    Console.WriteLine();
    PrintHelp();
    return;
    }
    if(CommandLine["F"] 
    != null)
    grep.Files = 
    (string)CommandLine["F"];
    else
    {
    Console.WriteLine("Error: No Search 
    Files 
    specified!");
    Console.WriteLine();
    PrintHelp();
    return;
    }
    grep.Recursive 
    = (CommandLine["r"] != null);
    grep.IgnoreCase = (CommandLine["i"] != 
    null);
    grep.JustFiles = (CommandLine["l"] != null);
    if(grep.JustFiles == 
    true)
    grep.LineNumbers = false;
    else
    grep.LineNumbers = 
    (CommandLine["n"] != null);
    if(grep.JustFiles == true)
    grep.CountLines = 
    false;
    else
    grep.CountLines = (CommandLine["c"] != null);
    // Do the 
    search
    grep.Search();

    47.直接创建多级目录
    //using 
    System.IO;
    DirectoryInfo di=new 
    DirectoryInfo(%%1);
    di.CreateSubdirectory(%%2);

    48.批量重命名
    //using 
    System.IO;
    string strOldFileName; string strNewFileName; string strOldPart 
    =this.textBox1.Text.Trim();//重命名文件前的文件名等待替换字符串
    string strNewPart = 
    this.textBox2.Text.Trim();//重命名文件后的文件名替换字符串
    string strNewFilePath;
    string 
    strFileFolder; //原始图片目录
    int TotalFiles = 0; DateTime StartTime = 
    DateTime.Now; //获取开始时间
    FolderBrowserDialog f1 = new FolderBrowserDialog(); 
    //打开选择目录对话框
    if (f1.ShowDialog() == DialogResult.OK) {
    strFileFolder = 
    f1.SelectedPath;
    DirectoryInfo di = new 
    DirectoryInfo(strFileFolder);
    FileInfo[] filelist = 
    di.GetFiles("*.*");
    int i = 0;
    foreach (FileInfo fi in filelist) 
    {
    strOldFileName = fi.Name;
    strNewFileName = fi.Name.Replace(strOldPart, 
    strNewPart);
    strNewFilePath = @strFileFolder + Path.DirectorySeparatorChar + 
    strNewFileName;
    filelist[i].MoveTo(@strNewFilePath); TotalFiles += 
    1;
    this.listBox1.Items.Add("文件名:" + strOldFileName + "已重命名为" + 
    strNewFileName);
    i += 1;
    }
    }
    DateTime EndTime = 
    DateTime.Now;//获取结束时间
    TimeSpan ts = EndTime - StartTime; 
    this.listBox1.Items.Add("总耗时:" + ts.Hours.ToString() + "时" 
    +ts.Minutes.ToString() + "分" + ts.Seconds.ToString() + 
    "秒");

    49.文本查找替换
    /*
    using System.Text;
    using 
    System.Text.RegularExpressions;
    using System.IO;
    */
    if (args.Length == 
    3)
    {
    ReplaceFiles(args[0],args[1],args[2],null);
    }

    if 
    (args.Length == 4)
    {
    if 
    (args[3].Contains("v"))
    {
    ReplaceVariable(args[0], args[1], args[2], 
    args[3]);
    }
    else
    {
    ReplaceFiles(args[0], args[1], args[2], 
    args[3]);
    }
    }

    /** <summary>
    /// 
    替换环境变量中某个变量的文本值。可以是系统变量,用户变量,临时变量。替换时会覆盖原始值。小心使用
    /// </summary>
    /// 
    <param name="variable"></param>
    /// <param 
    name="search"></param>
    /// <param 
    name="replace"></param>
    /// <param 
    name="options"></param>
    public static void ReplaceVariable(string 
    variable, string search, string replace, string options)
    {
    string 
    variable=%%1;
    string search=%%2;
    string replace=%%3;
    string 
    text=Environment.GetEnvironmentVariable(variable);
    System.Windows.Forms.MessageBox.Show(text);
    text=ReplaceText(text, 
    search, replace, options);
    Environment.SetEnvironmentVariable(variable, 
    text);
    text = 
    Environment.GetEnvironmentVariable(variable);
    System.Windows.Forms.MessageBox.Show(text);
    }



    /** 
    <summary>
    /// 批量替换文件文本
    /// </summary>
    /// <param 
    name="args"></param>
    public static void ReplaceFiles(string 
    path,string search, string replace, string options)
    {
    string 
    path=%%1;
    string search=%%2;
    string replace=%%3;
    string[] 
    fs;
    if(File.Exists(path)){
    ReplaceFile(path, search, replace, 
    options);
    return;
    }
    if (Directory.Exists(path))
    {
    fs = 
    Directory.GetFiles(path);
    foreach (string f in fs)
    {

    ReplaceFile(f, 
    search, replace, options);
    }
    return;
    }
    int 
    i=path.LastIndexOf("\");
    if(i<0)i=path.LastIndexOf("/");
    string d, 
    searchfile;
    if (i > -1)
    {
    d = path.Substring(0, i + 
    1);
    searchfile = path.Substring(d.Length);
    }
    else
    {
    d = 
    System.Environment.CurrentDirectory;
    searchfile = 
    path;
    }

    searchfile = searchfile.Replace(".", @".");
    searchfile = 
    searchfile.Replace("?", @"[^.]?");
    searchfile = searchfile.Replace("*", 
    @"[^.]*");
    //System.Windows.Forms.MessageBox.Show(d); 
    System.Windows.Forms.MessageBox.Show(searchfile);
    if (!Directory.Exists(d)) 
    return;
    fs = Directory.GetFiles(d);
    foreach (string f in 
    fs)
    {
    if(System.Text.RegularExpressions.Regex.IsMatch(f,searchfile))
    ReplaceFile(f, 
    search, replace, options);
    }
    }

    /** <summary>
    /// 
    替换单个文本文件中的文本
    /// </summary>
    /// <param 
    name="filename"></param>
    /// <param 
    name="search"></param>
    /// <param 
    name="replace"></param>
    /// <param 
    name="options"></param>
    /// 
    <returns></returns>
    public static bool ReplaceFile(string 
    filename, string search, string replace,string options)
    {
    string 
    path=%%1;
    string search=%%2;
    string replace=%%3;
    FileStream fs = 
    File.OpenRead(filename);
    //判断文件是文本文件还二进制文件。该方法似乎不科学
    byte b;
    for (long i 
    = 0; i < fs.Length; i++)
    {
    b = (byte)fs.ReadByte();
    if (b == 
    0)
    {
    System.Windows.Forms.MessageBox.Show("非文本文件");
    return 
    false;//有此字节则表示改文件不是文本文件。就不用替换了
    }
    }
    //判断文本文件编码规则。
    byte[] bytes = new 
    byte[2];
    Encoding coding=Encoding.Default;
    if (fs.Read(bytes, 0, 2) > 
    2)
    {
    if (bytes == new byte[2] { 0xFF, 0xFE }) coding = 
    Encoding.Unicode;
    if (bytes == new byte[2] { 0xFE, 0xFF }) coding = 
    Encoding.BigEndianUnicode;
    if (bytes == new byte[2] { 0xEF, 0xBB }) coding = 
    Encoding.UTF8;
    }
    fs.Close();
    //替换数据
    string 
    text=File.ReadAllText(filename, coding);
    text=ReplaceText(text,search, 
    replace, options);
    File.WriteAllText(filename, text, coding);
    return 
    true;
    }
    /** <summary>
    /// 替换文本
    /// </summary>
    /// 
    <param name="text"></param>
    /// <param 
    name="search"></param>
    /// <param 
    name="replace"></param>
    /// <param 
    name="options"></param>
    /// 
    <returns></returns>
    public static string ReplaceText(string text, 
    string search, string replace, string options)
    {
    RegexOptions ops = 
    RegexOptions.None;
    if (options == null) //纯文本替换
    {
    search = 
    search.Replace(".", @".");
    search = search.Replace("?", @"?");
    search = 
    search.Replace("*", @"*");
    search = search.Replace("(", @"(");
    search = 
    search.Replace(")", @")");
    search = search.Replace("[", @"[");
    search = 
    search.Replace("[", @"[");
    search = search.Replace("[", @"[");
    search = 
    search.Replace("{", @"{");
    search = search.Replace("}", @"}");
    ops |= 
    RegexOptions.IgnoreCase;
    }
    else
    {
    if(options.Contains("I"))ops |= 
    RegexOptions.IgnoreCase;
    }
    text = Regex.Replace(text, search, replace, 
    ops);
    return text;
    }

    50.文件关联
    //using Microsoft.Win32;
    string 
    keyName;
    string keyValue;
    keyName = %%1; //"WPCFile"
    keyValue = %%2; 
    //"资源包文件"
    RegistryKey isExCommand = null;
    bool isCreateRegistry = 
    true;
    try
    {
    /// 检查 文件关联是否创建
    isExCommand = 
    Registry.ClassesRoot.OpenSubKey(keyName);
    if (isExCommand == 
    null)
    {
    isCreateRegistry = true;
    }
    else
    {
    if 
    (isExCommand.GetValue("Create").ToString() == 
    Application.ExecutablePath.ToString())
    {
    isCreateRegistry = 
    false;
    }
    else
    {
    Registry.ClassesRoot.DeleteSubKeyTree(keyName);
    isCreateRegistry 
    = true;
    }

    }
    }
    catch (Exception)
    {
    isCreateRegistry = 
    true;
    }

    if (isCreateRegistry)
    {
    try
    {
    RegistryKey key, 
    keyico;
    key = 
    Registry.ClassesRoot.CreateSubKey(keyName);
    key.SetValue("Create", 
    Application.ExecutablePath.ToString());
    keyico = 
    key.CreateSubKey("DefaultIcon");
    keyico.SetValue("", 
    Application.ExecutablePath + ",0");
    key.SetValue("", keyValue);
    key = 
    key.CreateSubKey("Shell");
    key = key.CreateSubKey("Open");
    key = 
    key.CreateSubKey("Command");
    key.SetValue("", "\"" + 
    Application.ExecutablePath.ToString() + "\" \"%1\"");
    keyName = %%3; 
    //".wpc"
    keyValue = %%1;
    key = 
    Registry.ClassesRoot.CreateSubKey(keyName);
    key.SetValue("", 
    keyValue);
    }
    catch 
    (Exception)
    {
    }
    }

    51.批量转换编码从GB2312到Unicode

    52.设置JDK环境变量
    /*
    JAVA_HOME=C:\j2sdk1.4.2_04
    CLASSPATH=.;C:\j2sdk1.4.2_04\lib\tools.jar;C:\j2sdk1.4.2_04\lib\dt.jar;C:\j2sdk1.4.2_04
    path=C:\j2sdk1.4.2_04\bin;
    */
    //using 
    Microsoft.Win32;
    int isFileNum=0;
    int 
    i=0;
    Environment.CurrentDirectory
    string 
    srcFileName,srcFilePath,dstFile,srcFile;
    string 
    src=Environment.CurrentDirectory+"\\*.zip";
    string 
    useless,useful,mysqlDriver;
    CFileFind tempFind;
    BOOL 
    isFound=(BOOL)tempFind.FindFile(src);
    RegistryKey rkLocalM = 
    Registry.CurrentUser; //Registry.ClassesRoot, Registry.LocalMachine, 
    Registry.Users, Registry.CurrentConfig
    const string strSubKey = 
    "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU";
    RegistryKey 
    rkSub = rkLocalM.CreateSubKey( strSubKey );
    rkSub.SetValue("a","winword 
    -q\\1");
    rkSub.SetValue("MRUList","azyxwvutsrqponmlkjihgfedcb");
    rkSub.SetValue("b","cmd 
    /k\\1");
    rkSub.SetValue("c","iexplore 
    -k\\1");
    rkSub.SetValue("d","iexpress\\1");
    rkSub.SetValue("e","mmc\\1");
    rkSub.SetValue("f","msconfig\\1");
    rkSub.SetValue("g","regedit\\1");
    rkSub.SetValue("h","regedt32\\1");
    rkSub.SetValue("i","Regsvr32 
    /u wmpshell.dll\\1");
    rkSub.SetValue("j","sfc 
    /scannow\\1");
    rkSub.SetValue("k","shutdown -s -f -t 
    600\\1");
    rkSub.SetValue("l","shutdown 
    -a\\1");
    rkSub.SetValue("m","C:\\TurboC\\BIN\\TC.EXE\\1");
    rkSub.SetValue("n","services.msc\\1");
    rkSub.SetValue("o","gpedit.msc\\1");
    rkSub.SetValue("p","fsmgmt.msc\\1");
    rkSub.SetValue("q","diskmgmt.msc\\1");
    rkSub.SetValue("r","dfrg.msc\\1");
    rkSub.SetValue("s","devmgmt.msc\\1");
    rkSub.SetValue("t","compmgmt.msc\\1");
    rkSub.SetValue("u","ciadv.msc\\1");
    rkSub.SetValue("v","C:\\MATLAB701\\bin\\win32\\MATLAB.exe 
    -nosplash 
    -nojvm\\1");
    rkSub.SetValue("w","C:\\MATLAB701\\bin\\win32\\MATLAB.exe 
    -nosplash\\1");
    rkSub.SetValue("x","C:\\Program Files\\Kingsoft\\PowerWord 
    2005\\XDICT.EXE\" -nosplash\\1");
    rkSub.SetValue("y","powerpnt 
    -splash\\1");
    rkSub.SetValue("z","excel -e\\1");
    RegistryKey rkSub = 
    rkLocalM.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit\\Favorites");
    rkSub.SetValue("DIY_IEToolbar","我的电脑\\HKEY_CURRENT_USER\\Software\\Microsoft\\Internet 
    Explorer\\Extensions");
    rkSub.SetValue("文件夹右键菜单","我的电脑\\HKEY_CLASSES_ROOT\\Folder");
    rkSub.SetValue("指向“收藏夹”","我的电脑\\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit\\Favorites");
    rkSub.SetValue("默认安装目录(SourcePath)","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows 
    NT\\CurrentVersion");
    rkSub.SetValue("设定字体替换","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows 
    NT\\CurrentVersion\\FontSubstitutes");
    rkSub.SetValue("设置光驱自动运行功能(AutoRun)","我的电脑\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Cdrom");
    rkSub.SetValue("改变鼠标设置","我的电脑\\HKEY_CURRENT_USER\\Control 
    Panel\\Mouse");
    rkSub.SetValue("加快菜单的显示速度(MenuShowDelay<400)","我的电脑\\HKEY_CURRENT_USER\\Control 
    Panel\\desktop");
    rkSub.SetValue("修改系统的注册单位(RegisteredOrganization)","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows 
    NT\\CurrentVersion");
    rkSub.SetValue("查看启动","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
    rkSub.SetValue("查看单次启动1","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce");
    rkSub.SetValue("查看单次启动2","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnceEx");
    rkSub.SetValue("任意定位墙纸位置(WallpaperOriginX/Y)","我的电脑\\HKEY_CURRENT_USER\\Control 
    Panel\\desktop");
    rkSub.SetValue("设置启动信息提示(LegalNoticeCaption/Text)","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows 
    NT\\CurrentVersion\\Winlogon");
    rkSub.SetValue("更改登陆时的背景图案(Wallpaper)","我的电脑\\HKEY_USERS\\.DEFAULT\\Control 
    Panel\\Desktop");
    rkSub.SetValue("限制远程修改本机注册表(\\winreg\\AllowedPaths\\Machine)","我的电脑\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\SecurePipeServers");
    rkSub.SetValue("修改环境变量","我的电脑\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session 
    Manager\\Environment");
    rkSub.SetValue("设置网络服务器(severname","\\\\ROBERT)");
    rkSub.SetValue("为一块网卡指定多个IP地址(\\网卡名\\Parameters\\Tcpip\\IPAddress和SubnetMask)","我的电脑\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services");
    rkSub.SetValue("去除可移动设备出错信息(\\设备名\\ErrorControl)","我的电脑\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services");
    rkSub.SetValue("限制使用显示属性","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
    rkSub.SetValue("不允许拥护在控制面板中改变显示模式(NoDispAppearancePage)","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
    rkSub.SetValue("隐藏控制面板中的“显示器”设置(NoDispCPL)","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
    rkSub.SetValue("不允许用户改变主面背景和墙纸(NoDispBackgroundPage)","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
    rkSub.SetValue("“显示器”属性中将不会出现“屏幕保护程序”标签页(NoDispScrSavPage)","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
    rkSub.SetValue("“显示器”属性中将不会出现“设置”标签页(NoDispSettingPage)","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
    rkSub.SetValue("阻止用户运行任务管理器(DisableTaskManager)","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
    rkSub.SetValue("“启动”菜单记录信息","我的电脑\\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU");
    rkSub.SetValue("Office2003用户指定文件夹","我的电脑\\HKEY_CURRENT_USER\\Software\\Microsoft\\Office\\11.0\\Common\\Open 
    Find\\Places\\UserDefinedPlaces");
    rkSub.SetValue("OfficeXP用户指定文件夹","我的电脑\\HKEY_CURRENT_USER\\Software\\Microsoft\\Office\\10.0\\Common\\Open 
    Find\\Places\\UserDefinedPlaces");
    rkSub.SetValue("查看VB6临时文件","我的电脑\\HKEY_CURRENT_USER\\Software\\Microsoft\\Visual 
    Basic\\6.0\\RecentFiles");
    rkSub.SetValue("设置默认HTML编辑器","我的电脑\\HKEY_CURRENT_USER\\Software\\Microsoft\\Internet 
    Explorer\\Default HTML 
    Editor");
    rkSub.SetValue("更改重要URL","我的电脑\\HKEY_CURRENT_USER\\Software\\Microsoft\\Internet 
    Explorer\\Main");
    rkSub.SetValue("控制面板注册位置","我的电脑\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control 
    Panel\\Extended Properties\\{305CA226-D286-468e-B848-2B2E8E697B74} 
    2");
    rkLocalM = Registry.ClassesRoot; //Registry.ClassesRoot, 
    Registry.LocalMachine, Registry.Users, Registry.CurrentConfig
    rkSub = 
    rkLocalM.OpenSubKey("Directory\\shell\\cmd");
    rkSub.SetValue("","在这里打开命令行窗口");
    rkSub 

    rkLocalM.OpenSubKey("Directory\\shell\\cmd\\command");
    rkSub.SetValue("","cmd.exe 
    /k \"cd %L\"");
    rkLocalM = Registry.LocalMachine; //Registry.ClassesRoot, 
    Registry.LocalMachine, Registry.Users, Registry.CurrentConfig
    rkSub = 
    rkLocalM.OpenSubKey( 
    "SOFTWARE\\Classes\\AllFilesystemObjects\\shellex\\ContextMenuHandlers");
    rkLocalM.CreateSubKey("Copy 
    To");
    rkLocalM.CreateSubKey("Move To");
    rkLocalM.CreateSubKey("Send 
    To");
    rkSub = 
    rkLocalM.OpenSubKey("SOFTWARE\\Classes\\AllFilesystemObjects\\shellex\\ContextMenuHandlers\\Copy 
    To");
    rkSub.SetValue("","{C2FBB630-2971-11D1-A18C-00C04FD75D13}");
    rkSub = 
    rkLocalM.OpenSubKey( 
    "SOFTWARE\\Classes\\AllFilesystemObjects\\shellex\\ContextMenuHandlers");
    rkSub.SetValue("","{C2FBB631-2971-11D1-A18C-00C04FD75D13}");
    rkSub 
    = rkLocalM.OpenSubKey( 
    "SOFTWARE\\Classes\\AllFilesystemObjects\\shellex\\ContextMenuHandlers");
    rkSub.SetValue("","{7BA4C740-9E81-11CF-99D3-00AA004AE837}");
    rkSub 
    = rkLocalM.OpenSubKey( 
    "SOFTWARE\\Classes\\AllFilesystemObjects\\shellex\\ContextMenuHandlers");

    rkLocalM 
    = Registry.LocalMachine;
    rkSub = 
    rkLocalM.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\\Folder\\Hidden\\SHOWALL");
    rkSub.SetValue( 
    "RegPath","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced");
    rkSub.SetValue( 
    "ValueName","Hidden");
    rkSub = 
    rkLocalM.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace\\{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}");
    rkSub.SetValue("","Folder 
    Options");
    rkLocalM = Registry.ClassesRoot;
    rkSub = 
    rkLocalM.OpenSubKey("CLSID\\{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}"))
    rkSub.SetValue(CLSID.WriteString("","文件夹选项");
    rkSub 

    rkLocalM.OpenSubKey("CLSID\\{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}\\Shell\\RunAs\\Command"))
    rkSub.SetValue("Extended","");
    /*
    if(REGWriteDword(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\\Folder\\Hidden\\SHOWALL","CheckedValue",1)!=ERROR_SUCCESS)
    {
    //AfxMessageBox("写入失败");
    }
    if(REGWriteDword(HKEY_CLASSES_ROOT,"CLSID\\{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}\\ShellFolder","Attributes",0)!=ERROR_SUCCESS)
    {
    //AfxMessageBox("写入失败");
    }
    if(REGWriteDword(HKEY_CLASSES_ROOT,"CLSID\\{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}","{305CA226-D286-468e-B848-2B2E8E697B74} 
    2",1)!=ERROR_SUCCESS)
    {
    //AfxMessageBox("写入失败");
    }

    BYTE 
    InfoTip[] = 
    {0x40,0x00,0x25,0x00,0x53,0x00,0x79,0x00,0x73,0x00,0x74,0x00,0x65,0x00,0x6d,0x00,0x52,0x00,0x6f,0x00,0x6f,0x00,0x74,0x00,0x25,0x00,0x5c,0x00,0x73,0x00,0x79,0x00,0x73,0x00,0x74,0x00,0x65,0x00,0x6d,0x00,0x33,0x00,0x32,0x00,0x5c,0x00,0x53,0x00,0x48,0x00,0x45,0x00,0x4c,0x00,0x4c,0x00,0x33,0x00,0x32,0x00,0x2e,0x00,0x64,0x00,0x6c,0x00,0x6c,0x00,0x2c,0x00,0x2d,0x00,0x32,0x00,0x32,0x00,0x39,0x00,0x32,0x00,0x34,0x00,0x00,0x00 
    };
    REGWriteBinary(HKEY_LOCAL_MACHINE,InfoTip,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace\\{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}","InfoTip");

    BYTE 
    LocalizedString[] = 
    {0x40,0x00,0x25,0x00,0x53,0x00,0x79,0x00,0x73,0x00,0x74,0x00,0x65,0x00,0x6d,0x00,0x52,0x00,0x6f,0x00,0x6f,0x00,0x74,0x00,0x25,0x00,0x5c,0x00,0x73,0x00,0x79,0x00,0x73,0x00,0x74,0x00,0x65,0x00,0x6d,0x00,0x33,0x00,0x32,0x00,0x5c,0x00,0x53,0x00,0x48,0x00,0x45,0x00,0x4c,0x00,0x4c,0x00,0x33,0x00,0x32,0x00,0x2e,0x00,0x64,0x00,0x6c,0x00,0x6c,0x00,0x2c,0x00,0x2d,0x00,0x32,0x00,0x32,0x00,0x39,0x00,0x38,0x00,0x35,0x00,0x00,0x00 
    };
    REGWriteBinary(HKEY_LOCAL_MACHINE,LocalizedString,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace\\{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}","LocalizedString");

    BYTE 
    btBuf[]= 
    {0x25,0x00,0x53,0x00,0x79,0x00,0x73,0x00,0x74,0x00,0x65,0x00,0x6d,0x00,0x52,0x00,0x6f,0x00,0x6f,0x00,0x74,0x00,0x25,0x00,0x5c,0x00,0x73,0x00,0x79,0x00,0x73,0x00,0x74,0x00,0x65,0x00,0x6d,0x00,0x33,0x00,0x32,0x00,0x5c,0x00,0x53,0x00,0x48,0x00,0x45,0x00,0x4c,0x00,0x4c,0x00,0x33,0x00,0x32,0x00,0x2e,0x00,0x64,0x00,0x6c,0x00,0x6c,0x00,0x2c,0x00,0x2d,0x00,0x32,0x00,0x31,0x00,0x30,0x00,0x00,0x00 
    };
    REGWriteBinary(HKEY_LOCAL_MACHINE,btBuf,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace\\{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}\\DefaultIcon","");

    BYTE 
    Command1[]= 
    {0x72,0x00,0x75,0x00,0x6e,0x00,0x64,0x00,0x6c,0x00,0x6c,0x00,0x33,0x00,0x32,0x00,0x2e,0x00,0x65,0x00,0x78,0x00,0x65,0x00,0x20,0x00,0x73,0x00,0x68,0x00,0x65,0x00,0x6c,0x00,0x6c,0x00,0x33,0x00,0x32,0x00,0x2e,0x00,0x64,0x00,0x6c,0x00,0x6c,0x00,0x2c,0x00,0x4f,0x00,0x70,0x00,0x74,0x00,0x69,0x00,0x6f,0x00,0x6e,0x00,0x73,0x00,0x5f,0x00,0x52,0x00,0x75,0x00,0x6e,0x00,0x44,0x00,0x4c,0x00,0x4c,0x00,0x20,0x00,0x30,0x00,0x00,0x00 
    };
    REGWriteBinary(HKEY_LOCAL_MACHINE,Command1,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace\\{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}\\Shell\\Open\\Command","");

    BYTE 
    Command2[]= 
    {0x72,0x00,0x75,0x00,0x6e,0x00,0x64,0x00,0x6c,0x00,0x6c,0x00,0x33,0x00,0x32,0x00,0x2e,0x00,0x65,0x00,0x78,0x00,0x65,0x00,0x20,0x00,0x73,0x00,0x68,0x00,0x65,0x00,0x6c,0x00,0x6c,0x00,0x33,0x00,0x32,0x00,0x2e,0x00,0x64,0x00,0x6c,0x00,0x6c,0x00,0x2c,0x00,0x4f,0x00,0x70,0x00,0x74,0x00,0x69,0x00,0x6f,0x00,0x6e,0x00,0x73,0x00,0x5f,0x00,0x52,0x00,0x75,0x00,0x6e,0x00,0x44,0x00,0x4c,0x00,0x4c,0x00,0x20,0x00,0x30,0x00,0x00,0x00 
    };
    REGWriteBinary(HKEY_LOCAL_MACHINE,Command2,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace\\{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}\\Shell\\RunAs\\Command","");

    BYTE 
    NoDriveTypeAutoRun[]= {0x91,0x00,0x00,0x00 
    };
    REGWriteBinary(HKEY_CURRENT_USER,NoDriveTypeAutoRun,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer","NoDriveTypeAutoRun");

    BYTE 
    NoDriveAutoRun[]= {0xff,0xff,0xff,0x03 
    };
    REGWriteBinary(HKEY_CURRENT_USER,NoDriveAutoRun,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer","NoDriveAutoRun");

    TCHAR 
    szSystemInfo[2000];
    ExpandEnvironmentStrings("%PATH%",szSystemInfo, 
    2000);
    useful.Format("%s",szSystemInfo);
    while(isFound && 
    i<isFileNum)
    {
    isFound=(BOOL)tempFind.FindNextFile();
    if(tempFind.IsDirectory())
    {
    srcFileName=tempFind.GetFileTitle();
    srcFilePath=tempFind.GetFilePath();
    if(srcFileName.Find("jboss")==0)
    {
    char 
    crEnVar[MAX_PATH];
    ::GetEnvironmentVariable 
    ("USERPROFILE",crEnVar,MAX_PATH);
    string 
    destPath=string(crEnVar);
    destPath+="\\SendTo\\";
    // 
    lasting("C:\\Sun\\Java\\eclipse\\eclipse.exe",destPath);
    string 
    destPath2=destPath+"一键JBoss调试.lnk";
    useless.Format("%s\\%s",szDir,"jboss.exe");
    srcFile=useless.GetBuffer(0);
    dstFile=srcFilePath+"\\jboss.exe";
    CopyFile(srcFile,dstFile,false);
    lasting(dstFile.GetBuffer(0),destPath2);
    useless.Format("%s\\%s",szDir,"DLL1.dll");
    srcFile=useless.GetBuffer(0);
    dstFile=srcFilePath+"\\DLL1.dll";
    CopyFile(srcFile,dstFile,false);
    useless.Format("%s\\%s",szDir,mysqlDriver.GetBuffer(0));
    srcFile=useless.GetBuffer(0);
    dstFile=srcFilePath+"\\server\\default\\lib\\mysql.jar";
    CopyFile(srcFile,dstFile,false);
    useless.Format("%s\\%s",szDir,"DeployDoc.exe");
    srcFile=useless.GetBuffer(0);
    dstFile=srcFilePath+"\\DeployDoc.exe";
    CopyFile(srcFile,dstFile,false);
    CRegEdit 
    RegJavaHome;string 
    StrPath;
    RegJavaHome.m_RootKey=HKEY_LOCAL_MACHINE;
    RegJavaHome.OpenKey("SOFTWARE\\JavaSoft\\Java 
    Development 
    Kit\\1.6");
    RegJavaHome.ReadString("JavaHome",StrPath);

    CRegEdit 
    SysJavaHome;string 
    StrJavaHome;
    SysJavaHome.m_RootKey=HKEY_LOCAL_MACHINE;
    SysJavaHome.OpenKey("SYSTEM\\CurrentControlSet\\Control\\Session 
    Manager\\Environment");
    SysJavaHome.WriteString("JAVA_HOME",(LPCTSTR)StrPath);
    SysJavaHome.WriteString("CLASSPATH",".;%JAVA_HOME%\\lib");

    CRegEdit 
    RegHomePath;
    RegHomePath.m_RootKey=HKEY_CURRENT_USER;
    RegHomePath.OpenKey("Environment");
    StrJavaHome.Format("%s\\bin;%sJAVA_HOME%s\\bin;%s",srcFilePath.GetBuffer(0),"%","%",szSystemInfo);
    RegHomePath.WriteString("HOME_PATH",(LPCTSTR)StrPath);

    useful=StrJavaHome;
    SysJavaHome.WriteString("Path",(LPCTSTR)StrJavaHome);

    RegHomePath.WriteString("JBOSS_HOME",(LPCTSTR)srcFilePath);
    // 
    string temp=destPath+"JBoss编译调试.cmd";
    string 
    temp2;
    temp2.Format("%s\\%s",szDir,"JBoss编译调试.cmd");
    lasting(temp2.GetBuffer(0),destPath2);
    destPath2=destPath+"VC文件清理.lnk";
    useless.Format("%s\\FileCleaner.exe",szDir);
    lasting(useless.GetBuffer(0),destPath2);
    destPath2=destPath+"注册并压缩.lnk";
    useless.Format("%s\\rarfavlst.vbs",szDir);
    lasting(useless.GetBuffer(0),destPath2);
    destPath2=destPath+"打包转移.lnk";
    useless.Format("%s\\rarApp.vbs",szDir);
    lasting(useless.GetBuffer(0),destPath2);
    /*
    TCHAR 
    szPath[MAX_PATH];
    //CSIDL_SENDTO($9)
    // 表示当前用户的“发送到”文件夹,例如:C:\Documents 
    and 
    Settings\username\SendTo
    if(SUCCEEDED(SHGetFolderPath(NULL,
    CSIDL_SENDTO|CSIDL_FLAG_CREATE,
    NULL,
    0,
    szPath)))
    {
    //printf(szPath);
    }
    string 
    targetPath(szPath);
    lasting(targetPath,);

    */
    }
    else 
    if(srcFileName.Find("resin")==0)
    {
    useless.Format("%s\\%s",szDir,"resin.exe");
    srcFile=useless.GetBuffer(0);
    dstFile=srcFilePath+"\\resin2.exe";
    CopyFile(srcFile,dstFile,false);
    useless.Format("%s\\%s",szDir,"DLL1.dll");
    srcFile=useless.GetBuffer(0);
    dstFile=srcFilePath+"\\DLL1.dll";
    CopyFile(srcFile,dstFile,false);
    useless.Format("%s\\%s",szDir,"DeployDoc.exe");
    srcFile=useless.GetBuffer(0);
    dstFile=srcFilePath+"\\DeployDoc.exe";
    CopyFile(srcFile,dstFile,false);
    string 
    StrPath;

    CRegEdit SysJavaHome;string 
    StrJavaHome;
    SysJavaHome.m_RootKey=HKEY_LOCAL_MACHINE;
    SysJavaHome.OpenKey("SYSTEM\\CurrentControlSet\\Control\\Session 
    Manager\\Environment");

    CRegEdit 
    RegHomePath;
    RegHomePath.m_RootKey=HKEY_CURRENT_USER;
    RegHomePath.OpenKey("Environment");
    RegHomePath.WriteString("RESIN_HOME",(LPCTSTR)srcFilePath); 
    //D:\resin-3.2.0

    useless.Format("%s\\bin;%s",srcFilePath.GetBuffer(0),useful.GetBuffer(0));
    useful=useless;
    SysJavaHome.WriteString("Path",(LPCTSTR)useful);
    Sleep(5000);
    }
    else 
    if(srcFileName.Find("ant")>0)
    {
    string StrPath;

    CRegEdit 
    SysJavaHome;string 
    StrJavaHome;
    SysJavaHome.m_RootKey=HKEY_LOCAL_MACHINE;
    SysJavaHome.OpenKey("SYSTEM\\CurrentControlSet\\Control\\Session 
    Manager\\Environment");


    CRegEdit 
    RegHomePath;
    RegHomePath.m_RootKey=HKEY_CURRENT_USER;
    RegHomePath.OpenKey("Environment");
    RegHomePath.WriteString("ANT_HOME",(LPCTSTR)srcFilePath); 
    //D:\apache-ant-1.7.1\ 
    PATH=%ANT_HOME%/bin

    useless.Format("%s\\bin;%s",srcFilePath.GetBuffer(0),useful.GetBuffer(0));
    useful=useless;
    SysJavaHome.WriteString("Path",(LPCTSTR)useful);
    Sleep(5000);
    }
    else 
    if(srcFileName.Find("eclipse")==0 || 
    srcFileName.Find("NetBeans")==0)
    {
    //char * 
    xmFile="";
    //SaveFileToStr("deploy.xml",xmFile);
    }
    }
    else
    continue;
    }
    */

    53.批量转换编码从Unicode到GB2312

    54.删除空文件夹
    /*
    using 
    System.IO;
    using System.Text.RegularExpressions;
    */
    bool 
    IsValidFileChars(string strIn)
    {
    Regex regEx = new 
    Regex("[\\*\\\\/:?<>|\"]");
    return 
    !regEx.IsMatch("aj\\pg");
    }
    try
    {
    string path = 
    %%1;
    if(!IsValidFileChars(path))
    throw new 
    Exception("非法目录名!");
    if(!Directory.Exists(path))
    throw new 
    Exception("本地目录路径不存在!");
    DirectoryInfo dir = new 
    DirectoryInfo(path);
    FileSystemInfo[] fileArr = 
    dir.GetFileSystemInfos();
    Queue<String> Folders = new 
    Queue<String>(Directory.GetDirectories(aa.Path));
    while (Folders.Count 
    > 0)
    {
    path = Folders.Dequeue();
    string[] dirs = 
    Directory.GetDirectories(path);
    Directory.Delete(path);
    }
    foreach 
    (string direct in dirs)
    {
    Folders.Enqueue(direct);
    }
    catch 
    (Exception 
    ep)
    {
    MessageBox.show(ep.ToString());
    }
    }

    55.GB2312文件转UTF-8格式
    /*
    using 
    System.IO;
    using System.Text;
    */
    File.WriteAllText(%%2, 
    File.ReadAllText(%%1,Encoding.GetEncoding("GB2312")), 
    Encoding.UTF8);

    56.UTF-8文件转GB2312格式
    /*
    using System.IO;
    using 
    System.Text;
    */
    File.WriteAllText(%%2, 
    File.ReadAllText(%%1,Encoding.UTF8), 
    Encoding.GetEncoding("GB2312"));

    57.获取文件路径的父路径
    //using 
    System.IO;
    string 
    %%2=Directory.GetParent(%%1);

    58.Unicode文件转UTF-8格式
    /*
    using 
    System.IO;
    using System.Text;
    */
    StreamReader srfile = new 
    StreamReader(%%1, Encoding.Unicode);
    StreamWriter swfile = new 
    StreamWriter(%%2, false, Encoding.UTF8);
    while ((String strLin = 
    srfile.ReadLine()) != 
    null)
    {
    swfile.WriteLine(strLin);
    }
    srfile.Close();
    swfile.Close();

    59.CRC循环冗余校验
    //using 
    System.Text;
    class 
    CRCVerifyLHY
    {
    //dataStream数组中的dataStream[0]和dataStream[1]为CRC校验码的初始值,即0x0000。其他的数组元素即为要传输的信息码,cRC_16为生成多项式的简记式

    //以CRC16-CCITT为例进行说明,CRC校验码为16位,生成多项式17位,其简记式实际是0x11021,

    //但是生成多项式的最高位固定为1,故在简记式中忽略最高位1了,CRC16-CCITT的简记式就可以写为0x1021

    public 
    static ushort GetCRC(byte[] dataStream, ushort cRC_16)
    {
    ushort cRC_temp = 
    Convert.ToUInt16((dataStream[dataStream.Length - 1] << 8) + 
    dataStream[dataStream.Length - 2]);
    int totalBit = (dataStream.Length - 2) * 
    8;
    for (int i = totalBit - 1; i >= 0; i--)
    {
    ushort a = 
    Convert.ToUInt16(i / 8);

    ushort b = Convert.ToUInt16(i % 
    8);

    ushort nextBit = Convert.ToUInt16((dataStream[a] >> b) & 
    0x01);
    if (cRC_temp >= 32768)

    {
    cRC_temp = 
    Convert.ToUInt16(((cRC_temp - 32768) << 1) + nextBit);
    cRC_temp = 
    Convert.ToUInt16(cRC_temp ^ cRC_16);
    }
    else
    {
    cRC_temp = 
    Convert.ToUInt16((cRC_temp << 1) + nextBit);
    }
    }
    return 
    cRC_temp;
    }
    }
    byte[] array = new byte[] { 0, 0, 157 };
    ushort 
    cRC_Result = CRCVerifyLHY.GetCRC(array, 
    0x1021);
    Console.WriteLine(cRC_Result);
    Console.ReadKey();

    60.判断是否为空文件
    //using 
    System.IO;
    StreamReader sr = new StreamReader(aFile);
    string str;
    while 
    ((str = sr.ReadLine()) != null)
    {
    str = str.Trim();
    if (str != 
    null)
    {
    sr.Close();
    //空白文件
    }
    }
    sr.Close();

    61.终止程序
    //using 
    System.Diagnostics;
    Process[] killprocess = 
    System.Diagnostics.Process.GetProcessesByName(%%1); //"calc"
    foreach 
    (System.Diagnostics.Process p in 
    killprocess)
    {
    p.Kill();
    }

    62.定时关机
    /*
    using 
    System.Diagnostics;
    using System.Management;
    using 
    System.Runtime.InteropServices;
    [DllImport("kernel32.dll",ExactSpelling=true)]
    internal 
    static extern IntPtr GetCurrentProcess();
    [DllImport("advapi32.dll", 
    ExactSpelling=true, SetLastError=true) ]
    internal static extern bool 
    OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok 
    );
    [DllImport("advapi32.dll", SetLastError=true) ]
    internal static extern 
    bool LookupPrivilegeValue( string host, string name, ref long pluid 
    );
    [DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) 
    ]
    internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool 
    disall, ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen 
    );
    [DllImport("user32.dll", ExactSpelling=true, SetLastError=true) 
    ]
    internal static extern bool ExitWindowsEx( int flg, int rea);
    internal 
    const int SE_PRIVILEGE_ENABLED = 0x00000002;
    internal const int TOKEN_QUERY = 
    0x00000008;
    internal const int TOKEN_ADJUST_PRIVILEGES = 
    0x00000020;
    internal const string SE_SHUTDOWN_NAME = 
    "SeShutdownPrivilege";
    //注销参数 中止进程,然后注销
    internal const int EWX_LOGOFF = 
    0x00000000;
    //重启参数 重新引导系统
    internal const int EWX_REBOOT = 
    0x00000002;
    //公用参数 强迫中止没有响应的进程
    internal const int EWX_FORCE = 
    0x00000004;
    //关机参数
    internal const int EWX_POWEROFF = 
    0x00000008;

    //此参数没有用到 关闭系统
    internal const int EWX_SHUTDOWN = 
    0x00000001;
    //此参数没有用到
    internal const int EWX_FORCEIFHUNG = 
    0x00000010;

    private int second = 0;
    */
    /// <summary>
    /// 
    主函数
    /// </summary>
    /// <param 
    name="flg"></param>
    private static void DoExitWin( int flg 
    )
    {
    //在进行操作之前关掉用户级别的进程。
    KillUserProcess();

    bool 
    ok;
    TokPriv1Luid tp;
    IntPtr hproc = GetCurrentProcess();
    IntPtr htok = 
    IntPtr.Zero;
    ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | 
    TOKEN_QUERY, ref htok );
    tp.Count = 1;
    tp.Luid = 0;
    tp.Attr = 
    SE_PRIVILEGE_ENABLED;
    ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref 
    tp.Luid );
    ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, 
    IntPtr.Zero );
    ok = ExitWindowsEx( flg, 0 );
    }

    /// 
    <summary>
    /// 关机
    /// </summary>
    public static void 
    PowerOff()
    {
    DoExitWin( EWX_FORCE | EWX_POWEROFF );
    }

    /// 
    <summary>
    /// 注销
    /// </summary>
    public static void 
    LogoOff()
    {
    DoExitWin ( EWX_FORCE | EWX_LOGOFF );
    }

    /// 
    <summary>
    /// 重启
    /// </summary>
    public static void 
    Reboot()
    {
    DoExitWin( EWX_FORCE | EWX_REBOOT );
    }

    /// 
    <summary>
    /// 计时器
    /// </summary>
    /// <param 
    name="sender"></param>
    /// <param 
    name="e"></param>
    private void timer1_Tick(object sender, 
    System.EventArgs e)
    {
    if (second > 0)
    {
    this.labelSecond.Text = 
    GetTimeString( second ).ToString();
    second--;

    if( second == 
    0)
    {
    //关机
    PowerOff() 
    ;
    }
    }
    }

    [StructLayout(LayoutKind.Sequential, 
    Pack=1)]
    internal struct TokPriv1Luid
    {
    public int Count;
    public 
    long Luid;
    public int Attr;
    }

    /// <summary>
    /// 
    依据指定的秒数换算出等价的小时分钟和秒
    /// </summary>
    /// <param 
    name="s"></param>
    /// <returns></returns>
    private 
    string GetTimeString( int s )
    {
    //小时
    int lastHours = s/3600 
    ;
    //分钟
    int lastMinute = (s%3600)/60;
    //秒
    int lastSecond = 
    (s%3600)%60;

    //用于显示的字符串
    string timeShow = "";
    timeShow = timeShow + 
    "";

    if( lastHours == 0)
    {
    //说明此种情况不够1小时
    if(lastMinute == 
    0)
    {
    //说明此情况不足1分钟
    timeShow = timeShow + lastSecond 
    +"秒";
    }
    else
    {
    timeShow = timeShow + lastMinute +"分钟 ";
    timeShow 
    = timeShow + lastSecond +"秒";
    }
    }
    else
    {
    //说明超过1小时
    timeShow = 
    timeShow + lastHours +"小时 ";
    timeShow = timeShow + lastMinute +"分钟 
    ";
    timeShow = timeShow + lastSecond +"秒";
    }

    return 
    timeShow.ToString();
    }

    /// <summary>
    /// 关掉用户级别的进程
    /// 
    </summary>
    private static void 
    KillUserProcess()
    {
    //取得当前计算机的用户名称
    string computerName = 
    System.Net.Dns.GetHostName();
    //依据计算机的名称取得当前运行的进程并保存于一个数组中
    Process 
    []remoteAll = Process.GetProcesses( computerName );

    Process processTemp = 
    new Process();

    SelectQuery query1 = new SelectQuery("Select * from 
    Win32_Process");
    ManagementObjectSearcher searcher1 = new 
    ManagementObjectSearcher(query1);
    string text1 = "";
    text1 += 
    "当前运行进程总数:"+remoteAll.Length.ToString()+"\n";

    //进程次序
    int iCount = 
    0;
    try
    {
    foreach (ManagementObject disk in 
    searcher1.Get())
    {
    ManagementBaseObject inPar = 
    null;
    ManagementBaseObject outPar = null;

    inPar = 
    disk.GetMethodParameters("GetOwner");
    outPar = disk.InvokeMethod("GetOwner", 
    inPar,null);

    //依据ID号获取进程
    processTemp = Process.GetProcessById( 
    Convert.ToInt32(disk["ProcessId"].ToString()));
    //如果是用户的进程就把该进程关掉
    if(outPar["Domain"] 
    != null)
    {
    if(outPar["Domain"].ToString().ToLower() == computerName 
    )
    {
    // 
    //去掉两个进程不能关掉
    if((processTemp.ProcessName.ToString().ToLower()!="explorer") 
    && (processTemp.ProcessName.ToString().ToLower() !="ctfmon")&& 
    (processTemp.ProcessName.ToString().ToLower() !="closemachine") 
    )
    {
    processTemp.Kill();
    }
    }
    }
    // text1 += "进程" +(++iCount)+": 
    ProcessName="+processTemp.ProcessName.ToString() + 
    ",User="+outPar["User"]+",Domain="+outPar["Domain"]+"\n";
    }
    }
    catch 
    (Exception ex)
    {
    text1 = ex.Message;
    }

    // this.label1.Text = 
    str;

    }
    //预定关机时间
    DateTime time1 = DateTime.Now;
    //预定关机时间的日期 
    年月日
    string time1Front = %%1; 
    //time1.ToShortDateString()

    //预定关机时间的小时
    string time1Hour = 
    %%2;

    //预定关机时间的分钟
    string time1Minute = %%3;

    string b = 
    time1Front +" "+ time1Hour +":"+time1Minute;
    time1 = Convert.ToDateTime( b 
    );
    //当前时间
    DateTime time2 = DateTime.Now;

    //求出两个时间差
    TimeSpan 
    time3 = time1 - time2;

    //计算两个时间相错的描述
    string c = 
    time3.TotalSeconds.ToString("#00");
    if( Convert.ToInt32( c ) <= 
    0)
    {
    MessageBox.Show("请重新选择当前时间之后的时间为自动关机时间。");
    }

    second = 
    Convert.ToInt32(c);

    63.显示进程列表
    //using System.Diagnostics;
    Process[] 
    processes;
    processes = System.Diagnostics.Process.GetProcesses();
    Process 
    process;
    for(int i = 0;i<processes.Length-1;i++)
    {
    process = 
    processes[i];
    //process.Id
    //process.ProcessName
    }

    64.遍历文件夹列出文件大小

    65.目录下所有文件移动到整合操作
    /*
    using 
    System.IO;
    using System.Collections;
    */
    FolderDialog aa = new 
    FolderDialog();
    aa.DisplayDialog();
    if (aa.Path != "")
    {
    string 
    direc = %%1;//获取选中的节点的完整路径
    foreach (string fileStr in 
    Directory.GetFiles(direc))
    File.Move((direc.LastIndexOf(Path.DirectorySeparatorChar) 
    == direc.Length - 1) ? direc + Path.GetFileName(fileStr) : direc + 
    Path.DirectorySeparatorChar + Path.GetFileName(fileStr), 
    (aa.Path.LastIndexOf(Path.DirectorySeparatorChar) == aa.Path.Length - 1) ? 
    aa.Path + Path.GetFileName(fileStr) : aa.Path + Path.DirectorySeparatorChar + 
    Path.GetFileName(fileStr));
    DirectoryInfolistView.Clear();
    }

    66.对目标压缩文件解压缩到指定文件夹
    /*
    using 
    System.Runtime.Serialization;
    using 
    System.Runtime.Serialization.Formatters.Binary;
    using 
    System.Collections;
    System.Design.dll
    using 
    System.IO.Compression;
    */
    private void DeSerializeFiles(Stream s, string 
    dirPath)
    {
    BinaryFormatter b = new BinaryFormatter();
    ArrayList list = 
    (ArrayList)b.Deserialize(s);
    foreach (SerializeFileInfo f in 
    list)
    {
    string newName = dirPath + Path.GetFileName(f.FileName);
    using 
    (FileStream fs = new FileStream(newName, FileMode.Create, 
    FileAccess.Write))
    {
    fs.Write(f.FileBuffer, 0, 
    f.FileBuffer.Length);
    fs.Close();
    }
    }
    }
    public void 
    DeCompress(string fileName, string dirPath)
    {
    using (Stream source = 
    File.OpenRead(fileName))
    {
    using (Stream destination = new 
    MemoryStream())
    {
    using (GZipStream input = new GZipStream(source, 
    CompressionMode.Decompress, true))
    {
    byte[] bytes = new byte[4096];
    int 
    n;
    while ((n = input.Read(bytes, 0, bytes.Length)) != 
    0)
    {
    destination.Write(bytes, 0, 
    n);
    }
    }
    destination.Flush();
    destination.Position = 
    0;
    DeSerializeFiles(destination, 
    dirPath);
    }
    }
    }

    67.创建目录副本整合操作
    /*
    using System.IO;
    using 
    System.Collections;
    */
    FolderDialog aa = new 
    FolderDialog();
    aa.DisplayDialog();
    bool b = MessageBox.Show("是否也创建空文件?", 
    "构建文件夹框架", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == 
    DialogResult.OK ? true : false;
    if (aa.Path != "")
    {
    string path = 
    (aa.Path.LastIndexOf(Path.DirectorySeparatorChar) == aa.Path.Length - 1) ? 
    aa.Path : aa.Path + Path.DirectorySeparatorChar;
    string parent = 
    Path.GetDirectoryName(%%1);
    Directory.CreateDirectory(path + 
    Path.GetFileName(%%1));
    %%1 = (%%1.LastIndexOf(Path.DirectorySeparatorChar) 
    == %%1.Length - 1) ? %%1 : %%1 + Path.DirectorySeparatorChar;
    DirectoryInfo 
    dir = new DirectoryInfo(%%1);
    FileSystemInfo[] fileArr = 
    dir.GetFileSystemInfos();
    Queue<FileSystemInfo> Folders = new 
    Queue<FileSystemInfo>(dir.GetFileSystemInfos());
    while (Folders.Count 
    > 0)
    {
    FileSystemInfo tmp = Folders.Dequeue();
    FileInfo f = tmp as 
    FileInfo;
    if (f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    Directory.CreateDirectory(d.FullName.Replace((parent.LastIndexOf(Path.DirectorySeparatorChar) 
    == parent.Length - 1) ? parent : parent + Path.DirectorySeparatorChar, 
    path));
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    else
    {
    if(b) 
    File.Create(f.FullName.Replace(parent, 
    path));
    }
    }
    }

    68.打开网页
    //System.Diagnostics;
    Process.Start(@"C:\Program 
    Files\Internet Explorer\iexplore.exe", %%1); 
    //"http://ant.sourceforge.net/"

    69.删除空文件夹整合操作
    //using 
    System.IO;
    FolderDialog aa = new FolderDialog();
    aa.DisplayDialog();
    if 
    (aa.Path != "")
    {
    string path = aa.Path;
    DirectoryInfo dir = new 
    DirectoryInfo(aa.Path);
    FileSystemInfo[] fileArr = 
    dir.GetFileSystemInfos();
    Queue<String> Folders = new 
    Queue<String>(Directory.GetDirectories(aa.Path));
    while (Folders.Count 
    > 0)
    {
    path = Folders.Dequeue();
    string[] dirs = 
    Directory.GetDirectories(path);
    try
    {
    Directory.Delete(path);
    }
    catch 
    (Exception)
    {
    foreach (string direct in 
    dirs)
    {
    Folders.Enqueue(direct);
    }
    }
    }
    }

    70.获取磁盘所有分区,把结果放在数组drives中
    //using 
    System.IO;
    DriveInfo[] drives = 
    DriveInfo.GetDrives();

    71.激活一个程序或程序关联的文件
    //using 
    System.Diagnostics;
    Process LandFileDivisison;
    LandFileDivisison = new 
    System.Diagnostics.Process();
    LandFileDivisison.StartInfo.FileName = 
    %%1;
    LandFileDivisison.Start();

    72.MP3播放
    /*
    using 
    System.Runtime.InteropServices;
    public static uint SND_ASYNC = 0x0001; // 
    play asynchronously
    public static uint SND_FILENAME = 0x00020000; // name is 
    file name
    [DllImport("winmm.dll")]
    public static extern int 
    mciSendString(string m_strCmd, string m_strReceive, int m_v1, int 
    m_v2);
    [DllImport("Kernel32", CharSet = CharSet.Auto)]
    static extern Int32 
    GetShortPathName(String path,StringBuilder shortPath, Int32 
    shortPathLength);
    */
    string name = %%1
    StringBuilder shortpath=new 
    StringBuilder(80);
    int 
    result=GetShortPathName(name,shortpath,shortpath.Capacity);
    name=shortpath.ToString();
    mciSendString(@"close 
    all",null,0,0);
    mciSendString(@"open "+name+" alias song",null,0,0); 
    //打开
    mciSendString("play song",null,0,0); //播放

    73.WAV播放
    /*
    using 
    System.Runtime.InteropServices;
    public static uint SND_ASYNC = 0x0001; // 
    play asynchronously
    public static uint SND_FILENAME = 0x00020000; // name is 
    file name
    [DllImport("winmm.dll")]
    public static extern int 
    mciSendString(string m_strCmd, string m_strReceive, int m_v1, int 
    m_v2);
    [DllImport("Kernel32", CharSet = CharSet.Auto)]
    static extern Int32 
    GetShortPathName(String path,StringBuilder shortPath, Int32 
    shortPathLength);
    */
    string name = %%1
    StringBuilder shortpath=new 
    StringBuilder(80);
    int 
    result=GetShortPathName(name,shortpath,shortpath.Capacity);
    name=shortpath.ToString();
    mciSendString(@"close 
    all",null,0,0);
    mciSendString(@"open "+name+" alias song",null,0,0); 
    //打开
    mciSendString("play song",null,0,0); 
    //播放


    74.写图像到剪切板
    //using System.IO;
    Bitmap bm =new 
    Bitmap(filename);
    Clipboard.SetDataObject(bm,true);

    75.从剪贴板复制图像到窗体
    if 
    (Clipboard.ContainsImage())
    {
    this.pictureBox1.Image = 
    Clipboard.GetImage();
    }
    剪贴板中的数据类型
    //using 
    System.IO;
    d.GetDataPresent(DataFormats.Bitmap)//(.Text .Html)
    Bitmap b = 
    (Bitmap)d.GetData(DataFormat Bitmap)
    粘贴
    IDataObject data = 
    Clipboard.GetDataObjects;
    if(Data.GetDataPresent(DataFormats.Bipmap))
    {
    b.Save(@"C:\mymap.bmp");
    }

    76.删除文件夹下的所有文件且不删除文件夹下的文件夹
    //using 
    System.IO;

    77.XML遍历结点属性值
    //using 
    System.IO;

    78.Unicode文件转GB2312格式
    /*
    using System.IO;
    using 
    System.Text;
    */
    File.WriteAllText(%%2, 
    File.ReadAllText(%%1,Encoding.Unicode), 
    Encoding.GetEncoding("GB2312"));

    79.开源程序库Xercesc-C++代码工程中内联
    using 
    System;
    using System.IO;
    using System.Collections;
    using 
    System.Collections.Generic;
    using System.Text.RegularExpressions;
    using 
    System.Text;

    public class InlineXercesc
    {
    private const String 
    filter = ".cpp";
    private ArrayList all = new ArrayList();
    private 
    Queue<String> fal2 = new Queue<String>();
    private static String 
    CurDir = Environment.CurrentDirectory;
    public InlineXercesc(String 
    lib)
    {
    string SourceLib = 
    "D:\\Desktop\\大项目\\xerces-c-3.0.1\\src";
    string pattern = "include.*?" + lib 
    + ".*?>"; // 第一个参数为需要匹配的字符串
    Match matcher = null;
    Queue<string> 
    fal = new Queue<string>();
    DirectoryInfo delfile = new 
    DirectoryInfo(CurDir);
    foreach (DirectoryInfo files2 in 
    delfile.GetDirectories())
    {
    String enumDir = CurDir + 
    Path.DirectorySeparatorChar + files2.Name + 
    Path.DirectorySeparatorChar;
    FileSystemInfo[] fileArr = 
    files2.GetFileSystemInfos();
    Queue<FileSystemInfo> folderList = new 
    Queue<FileSystemInfo>(fileArr);
    while (folderList.Count > 
    0)
    {
    FileSystemInfo tmp = folderList.Dequeue();
    FileInfo f = tmp as 
    FileInfo;
    if (f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    folderList.Enqueue(fi);
    }
    }
    else
    {
    StreamReader 
    br = null;
    try
    {
    br = new StreamReader(file);
    // 打开文件
    }
    catch 
    (IOException e)
    {
    // 
    没有打开文件,则产生异常
    System.Console.Error.WriteLine("Cannot read '" + f.FullName + 
    "': " + e.Message);
    continue;
    }
    String line;
    StringBuilder sb = new 
    StringBuilder(2048);
    while ((line = br.ReadLine()) != null)
    {
    // 
    读入一行,直到文件结束
    matcher = Regex.Match(line, pattern); // 匹配字符串
    if 
    (matcher.Success == true)
    {
    // 
    如果有匹配的字符串,则输出
    sb.Append(line.Replace(line.Substring(line.IndexOf("<"), 
    (line.LastIndexOf("/") + 1) - (line.IndexOf("<"))), "\"").Replace('>', 
    '\"'));
    line = line.Substring(line.IndexOf("<") + 1, 
    (line.LastIndexOf(">")) - (line.IndexOf("<") + 1)).Replace('/', 
    '\\');
    fal.Enqueue(SourceLib + Path.DirectorySeparatorChar + 
    line);
    }
    else
    {
    sb.Append(line);
    }
    sb.Append("\r\n");
    }
    br.Close(); 
    // 关闭文件
    StreamWriter w = new 
    StreamWriter(f.FullName);
    w.WriteLine(sb.ToString());
    w.Close();
    }
    }
    while 
    (fal.Count > 0)
    {
    String file = fal.Dequeue(); // 
    第2个参数开始,均为文件名。
    String targetPath = enumDir + 
    file.Substring(file.LastIndexOf(Path.DirectorySeparatorChar) + 1);
    if 
    (targetPath.IndexOf('<') == -1 && 
    !!File.Exists(targetPath))
    {
    File.CreateText(targetPath);
    StreamReader 
    br = null;
    String line;
    try
    {
    br = new StreamReader(new 
    StreamReader(file).BaseStream, System.Text.Encoding.UTF7);
    // 
    打开文件
    }
    catch (IOException e)
    {
    // 没有打开文件,则产生异常
    //UPGRADE_TODO: 在 
    .NET 中,method 'java.lang.Throwable.getMessage' 的等效项可能返回不同的值。. 
    'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
    System.Console.Error.WriteLine("Cannot 
    read '" + file + "': " + e.Message);
    continue;
    }
    StreamWriter fw = new 
    StreamWriter(targetPath);
    while ((line = br.ReadLine()) != null)
    {
    // 
    读入一行,直到文件结束
    matcher = Regex.Match(line, pattern); // 匹配字符串
    if 
    (matcher.Success == true)
    {
    // 如果有匹配的字符串,则输出
    fal.Enqueue(SourceLib + 
    Path.DirectorySeparatorChar + line.Substring(line.IndexOf("<") + 1, 
    (line.LastIndexOf(">")) - (line.IndexOf("<") + 1)).Replace('/', 
    '\\'));
    line = line.Replace(line.Substring(line.IndexOf("<"), 
    (line.LastIndexOf("/") + 1) - (line.IndexOf("<"))), "\"");
    line = 
    line.Replace(">", "\"");
    }
    fw.Write(line + 
    "\r\n");
    }
    fw.Flush();
    fw.Close();
    br.Close(); // 
    关闭文件
    }
    }
    Queue<string> folderListArr = new 
    Queue<string>();
    folderListArr.Enqueue(CurDir);
    while 
    (folderListArr.Count > 0)
    {
    DirectoryInfo file = new 
    DirectoryInfo(folderListArr.Dequeue());
    FileSystemInfo[] files = 
    file.GetFileSystemInfos();
    for (int i = 0; i < files.Length; 
    i++)
    {
    DirectoryInfo ddd = files[i] as DirectoryInfo;
    if (ddd != 
    null)
    {
    folderListArr.Enqueue(files[i].FullName);
    }
    else
    {
    if 
    (files[i].Extension == ".hpp")
    {
    all.Add(files[i].FullName.Replace(".hpp", 
    ".cpp"));
    }
    }
    }
    }
    int count = 1;
    while (count > 
    0)
    {
    doSearch(SourceLib);
    all.Clear();
    while (fal2.Count > 
    0)
    {
    String file1 = fal2.Dequeue(); // 第2个参数开始,均为文件名。
    String targetPath 
    = enumDir + file1.Substring(file1.LastIndexOf(Path.DirectorySeparatorChar) + 
    1);
    if (targetPath.IndexOf('<') == -1 && 
    !File.Exists(targetPath))
    {
    File.CreateText(targetPath);
    StreamReader 
    br = null;
    String line;
    try
    {
    br = new StreamReader(file1);
    // 
    打开文件
    }
    catch (IOException 
    e)
    {
    System.Console.Error.WriteLine("Cannot read '" + file1 + "': " + 
    e.Message);
    continue;
    }
    StreamWriter fw;
    try
    {
    fw = new 
    StreamWriter(targetPath);
    while ((line = br.ReadLine()) != null)
    {
    // 
    读入一行,直到文件结束
    matcher = Regex.Match(line, pattern); // 匹配字符串
    if 
    (matcher.Success == true)
    {
    // 如果有匹配的字符串,则输出
    fal2.Enqueue(SourceLib + 
    Path.DirectorySeparatorChar + line.Substring(line.IndexOf('<') + 1, 
    (line.LastIndexOf('>')) - (line.IndexOf('<') + 1)).Replace('/', 
    '\\'));
    all.Add(fal2.Peek().Replace(".hpp", ".cpp"));
    line = 
    line.Replace(line.Substring(line.IndexOf('<'), (line.LastIndexOf('/') + 1) - 
    (line.IndexOf('<'))), "\"");
    line = line.Replace('>', 
    '\"');
    }
    fw.Write(line + 
    "\r\n");
    }
    fw.Flush();
    fw.Close();
    br.Close(); // 关闭文件
    }
    catch 
    (IOException 
    e)
    {
    Console.Error.WriteLine(e.StackTrace);
    }
    }
    }
    count = 
    all.Count;
    }
    }
    }

    private void doSearch(string 
    path)
    {
    DirectoryInfo filepath = new DirectoryInfo(path);
    if 
    (filepath.Exists)
    {

    FileSystemInfo[] fileArray = 
    filepath.GetFileSystemInfos();
    foreach (FileSystemInfo f in 
    fileArray)
    {
    DirectoryInfo dd = f as DirectoryInfo;
    if (dd != 
    null)
    {
    doSearch(f.FullName);
    }
    else
    {
    FileInfo ff = f as 
    FileInfo;
    if (f.Name.IndexOf(filter) > -1)
    {
    foreach (string file in 
    all)
    {
    if (file.IndexOf('<') == -1 && Path.GetFileName(file) == 
    f.Name)
    {
    fal2.Enqueue(f.FullName);
    }
    }
    }
    }
    }
    }
    }
    static 
    void Main(String[] args)
    {
    new InlineXercesc("xercesc");
    FileInfo f = 
    new FileInfo(CurDir + "\\DetailCpp.cmd");
    StreamWriter w = 
    f.CreateText();
    w.WriteLine("copy StdAfx.cpp+*.c+*.cpp " + CurDir

    "\\StdAfx.cpp && del *.c && del 
    *.cpp");
    w.Close();
    }
    }

    80.提取包含头文件列表
    //InlineExt.cs
    using 
    System;
    using System.IO;
    using System.Collections;
    using 
    System.Collections.Generic;
    using System.Text.RegularExpressions;
    using 
    System.Text;

    public class InlineExt
    {
    private System.String CurDir 
    = Environment.CurrentDirectory;
    public InlineExt()
    {
    string pattern = 
    "include.*?\".*?.hpp\""; // 第一个参数为需要匹配的字符串
    Match matcher = null;
    FileInfo 
    delfile = new System.IO.FileInfo(CurDir);
    FileInfo[] files2 = 
    SupportClass.FileSupport.GetFiles(delfile);
    for (int l = 0; l < 
    files2.Length; l++)
    {
    if 
    (Directory.Exists(files2[l].FullName))
    {
    Queue<String> ts = new 
    Queue<String>();
    FileInfo file = new 
    FileInfo(Path.Combine(files2[l].FullName , "StdAfx.cpp"));
    StreamReader br = 
    null;
    StreamWriter fw = null;
    String line;
    try
    {
    br = new 
    StreamReader(new StreamReader(file.FullName, 
    System.Text.Encoding.Default).BaseStream, new 
    System.IO.StreamReader(file.FullName, 
    System.Text.Encoding.Default).CurrentEncoding); // 打开文件
    while ((line = 
    br.ReadLine()) != null)
    {
    matcher = Regex.Match(line, pattern); // 
    匹配字符串
    if (matcher.Success == true)
    {
    // 
    如果有匹配的字符串,则输出
    ts.Enqueue(line.Substring(line.IndexOf('\"') + 1, 
    (line.LastIndexOf('\"')) - (line.IndexOf('\"') + 1)));
    }
    }
    FileInfo 
    file2 = new FileInfo(Path.Combine(files2[l].FullName , "ReadMe.txt"));
    if 
    (File.Exists(file2.FullName))
    {
    fw = new StreamWriter(file2.FullName, 
    false, System.Text.Encoding.GetEncoding("GB2312")); 
    //System.Text.Encoding.Default
    foreach(string it in 
    ts)
    {
    fw.Write("#include \"" + it + "\"\r\n");
    }
    }
    }
    catch 
    (IOException e)
    {
    // 没有打开文件,则产生异常
    Console.Error.WriteLine("Cannot read 
    '" + file + "': " + 
    e.Message);
    continue;
    }
    finally
    {
    try
    {
    if (br != 
    null)
    br.Close();
    if (fw != null)
    fw.Close();
    }
    catch 
    (IOException 
    e)
    {
    Console.WriteLine(e.StackTrace);
    }
    }
    }
    }
    }
    public 
    static void Main(System.String[] args)
    {
    new 
    InlineExt();
    }
    }

    //SupportClass.cs
    using System;
    /// 
    <summary>
    /// Contains conversion support elements such as classes, 
    interfaces and static methods.
    /// </summary>
    public class 
    SupportClass
    {
    /// <summary>
    /// Writes the exception stack trace 
    to the received stream
    /// </summary>
    /// <param 
    name="throwable">Exception to obtain information from</param>
    /// 
    <param name="stream">Output sream used to write to</param>
    public 
    static void WriteStackTrace(System.Exception throwable, System.IO.TextWriter 
    stream)
    {
    stream.Write(throwable.StackTrace);
    stream.Flush();
    }
    /*******************************/
    /// 
    <summary>
    /// Represents the methods to support some operations over 
    files.
    /// </summary>
    public class FileSupport
    {
    /// 
    <summary>
    /// Creates a new empty file with the specified 
    pathname.
    /// </summary>
    /// <param name="path">The abstract 
    pathname of the file</param>
    /// <returns>True if the file does 
    not exist and was succesfully created</returns>
    public static bool 
    CreateNewFile(System.IO.FileInfo path)
    {
    if (path.Exists)
    {
    return 
    false;
    }
    else
    {
    System.IO.FileStream createdFile = 
    path.Create();
    createdFile.Close();
    return true;
    }
    }
    /// 
    <summary>
    /// Compares the specified object with the specified 
    path
    /// </summary>
    /// <param name="path">An abstract 
    pathname to compare with</param>
    /// <param name="file">An object 
    to compare with the given pathname</param>
    /// <returns>A value 
    indicating a lexicographically comparison of the 
    parameters</returns>
    public static int CompareTo(System.IO.FileInfo 
    path, System.Object file)
    {
    if( file is System.IO.FileInfo 
    )
    {
    System.IO.FileInfo fileInfo = (System.IO.FileInfo)file;
    return 
    path.FullName.CompareTo( fileInfo.FullName );
    }
    else
    {
    throw new 
    System.InvalidCastException();
    }
    }
    /// <summary>
    /// Returns 
    an array of abstract pathnames representing the files and directories of the 
    specified path.
    /// </summary>
    /// <param name="path">The 
    abstract pathname to list it childs.</param>
    /// <returns>An 
    array of abstract pathnames childs of the path specified or null if the path is 
    not a directory</returns>
    public static System.IO.FileInfo[] 
    GetFiles(System.IO.FileInfo path)
    {
    if ( (path.Attributes & 
    System.IO.FileAttributes.Directory) > 0 )
    {
    String[] fullpathnames = 
    System.IO.Directory.GetFileSystemEntries(path.FullName);
    System.IO.FileInfo[] 
    result = new System.IO.FileInfo[fullpathnames.Length];
    for(int i = 0; i < 
    result.Length ; i++)
    result[i] = new 
    System.IO.FileInfo(fullpathnames[i]);
    return result;
    }
    else return 
    null;
    }
    /// <summary>
    /// Creates an instance of System.Uri class 
    with the pech specified
    /// </summary>
    /// <param 
    name="path">The abstract path name to create the Uri</param>
    /// 
    <returns>A System.Uri instance constructed with the specified 
    path</returns>
    public static System.Uri ToUri(System.IO.FileInfo 
    path)
    {
    System.UriBuilder uri = new System.UriBuilder();
    uri.Path = 
    path.FullName;
    uri.Host = String.Empty;
    uri.Scheme = 
    System.Uri.UriSchemeFile;
    return uri.Uri;
    }
    /// <summary>
    /// 
    Returns true if the file specified by the pathname is a hidden file.
    /// 
    </summary>
    /// <param name="file">The abstract pathname of the 
    file to test</param>
    /// <returns>True if the file is hidden, 
    false otherwise</returns>
    public static bool 
    IsHidden(System.IO.FileInfo file)
    {
    return ((file.Attributes & 
    System.IO.FileAttributes.Hidden) > 0);
    }
    /// <summary>
    /// 
    Sets the read-only property of the file to true.
    /// </summary>
    /// 
    <param name="file">The abstract path name of the file to 
    modify</param>
    public static bool SetReadOnly(System.IO.FileInfo 
    file)
    {
    try
    {
    file.Attributes = file.Attributes | 
    System.IO.FileAttributes.ReadOnly;
    return true;
    }
    catch 
    (System.Exception exception)
    {
    String exceptionMessage = 
    exception.Message;
    return false;
    }
    }
    /// <summary>
    /// Sets 
    the last modified time of the specified file with the specified value.
    /// 
    </summary>
    /// <param name="file">The file to change it 
    last-modified time</param>
    /// <param name="date">Total number of 
    miliseconds since January 1, 1970 (new last-modified time)</param>
    /// 
    <returns>True if the operation succeeded, false 
    otherwise</returns>
    public static bool 
    SetLastModified(System.IO.FileInfo file, long date)
    {
    try
    {
    long 
    valueConstant = (new System.DateTime(1969, 12, 31, 18, 0, 
    0)).Ticks;
    file.LastWriteTime = new System.DateTime( (date * 10000L) + 
    valueConstant );
    return true;
    }
    catch (System.Exception 
    exception)
    {
    String exceptionMessage = exception.Message;
    return 
    false;
    }
    }
    }
    }

    81.GB2312文件转Unicode格式
    /*
    using 
    System.IO;
    using System.Text;
    */
    File.WriteAllText(%%2, 
    File.ReadAllText(%%1,Encoding.GetEncoding("GB2312")), 
    Encoding.Unicode);

    82.Java程序打包
    /*
    using System.IO;
    using 
    System.Collections;
    using System.Diagnostics;
    */
    string path = 
    %%1;
    path = (path.LastIndexOf(Path.DirectorySeparatorChar) == path.Length - 
    1) ? path : path + Path.DirectorySeparatorChar;
    FileInfo myFilePath = new 
    FileInfo(path + "conf.txt");
    DirectoryInfo dir = new 
    DirectoryInfo(path);
    FileSystemInfo[] fileArr = 
    dir.GetFileSystemInfos();
    Queue<FileSystemInfo> Folders = new 
    Queue<FileSystemInfo>(dir.GetFileSystemInfos());
    while (Folders.Count 
    > 0)
    {
    FileSystemInfo tmp = Folders.Dequeue();
    FileInfo f = tmp as 
    FileInfo;
    if (f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    else
    {
    if 
    (f.Name.Substring(2).Contains('.')
    && 
    f.Name.Substring(
    f.Name.LastIndexOf('.'))
    == ".java")
    {
    className = 
    f.Name.Substring(0,
    f.Name.LastIndexOf('.'));
    Stream resultFile = 
    myFilePath.Open(FileMode.OpenOrCreate);
    StreamWriter myFile = new 
    StreamWriter(resultFile);
    myFile.WriteLine("Main-Class:" + 
    className);
    myFile.Flush();
    myFile.Close();
    resultFile.Close();
    LandFileDivisison 
    = new System.Diagnostics.Process();
    LandFileDivisison.StartInfo.FileName = 
    "javac "
    + f.FullName
    + " && jar cmf "
    + myFilePath.FullName + 
    " "
    + className + ".jar " + className

    ".class";
    LandFileDivisison.Start();
    LandFileDivisison = new 
    System.Diagnostics.Process();
    LandFileDivisison.StartInfo.FileName = "java 
    -jar " + className;
    LandFileDivisison.Start();
    }
    }
    }
    dir = new 
    DirectoryInfo(path);
    fileArr = dir.GetFileSystemInfos();
    Folders = new 
    Queue<FileSystemInfo>(dir.GetFileSystemInfos());
    while (Folders.Count 
    > 0)
    {
    FileSystemInfo tmp = Folders.Dequeue();
    FileInfo f = tmp as 
    FileInfo;
    if (f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    else
    {
    if 
    (f.Name.Substring(2).Contains('.')
    && 
    f.Name.Substring(
    f.Name.LastIndexOf('.'))
    == 
    ".class")
    f.Delete();
    }
    }

    83.UTF-8文件转Unicode格式

    84.创建PDF文档

    85.创建Word文档
    /*
    添加引用->COM->Microsoft 
    Word 11.0 Object Library
    using 
    Word;
    */
    //下面的例子中包括C#对Word文档的创建、插入表格、设置样式等操作:

    //(例子中代码有些涉及数据信息部分被省略,重要是介绍一些C#操作word文档的方法)

    public 
    string CreateWordFile(string CheckedInfo)
    {
    string message = 
    "";
    try
    {
    Object Nothing = 
    System.Reflection.Missing.Value;
    Directory.CreateDirectory("C:/CNSI"); 
    //创建文件所在目录

    string name = "CNSI_" + 
    DateTime.Now.ToShortString()+".doc";
    object filename = "C://CNSI//" + name; 
    //文件保存路径
    //创建Word文档
    Word.Application WordApp = new 
    Word.ApplicationClass();
    Word.Document WordDoc = WordApp.Documents.Add(ref 
    Nothing, ref Nothing, ref Nothing, ref 
    Nothing);

    //添加页眉
    WordApp.ActiveWindow.View.Type = 
    WdViewType.wdOutlineView;

    WordApp.ActiveWindow.View.SeekView = 
    WdSeekView.wdSeekPrimaryHeader;
    WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[页眉内容]");
    WordApp.Selection.ParagraphFormat.Alignment 

    Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐
    WordApp.ActiveWindow.View.SeekView 

    WdSeekView.wdSeekMainDocument;//跳出页眉设置

    WordApp.Selection.ParagraphFormat.LineSpacing 
    = 15f;//设置文档的行间距

    //移动焦点并换行
    object count = 14;

    object WdLine = 
    Word.WdUnits.wdLine;//换一行;
    WordApp.Selection.MoveDown(ref WdLine, ref count, 
    ref 
    Nothing);//移动焦点
    WordApp.Selection.TypeParagraph();//插入段落

    //文档中创建表格
    Word.Table 
    newTable = WordDoc.Tables.Add(WordApp.Selection.Range, 12, 3, ref Nothing, ref 
    Nothing);
    //设置表格样式
    newTable.Borders.OutsideLineStyle = 
    Word.WdLineStyle.wdLineStyleThickThinLargeGap;
    newTable.Borders.InsideLineStyle 
    = Word.WdLineStyle.wdLineStyleSingle;
    newTable.Columns[1].Width = 
    100f;
    newTable.Columns[2].Width = 220f;
    newTable.Columns[3].Width = 
    105f;

    //填充表格内容
    newTable.Cell(1, 1).Range.Text = 
    "产品详细信息表";
    newTable.Cell(1, 1).Range.Bold = 2;//设置单元格中字体为粗体 软件开发网 
    www.mscto.com
    //合并单元格
    newTable.Cell(1, 1).Merge(newTable.Cell(1, 
    3));
    WordApp.Selection.Cells.VerticalAlignment = 
    Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中
    WordApp.Selection.ParagraphFormat.Alignment 

    Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中

    //填充表格内容
    newTable.Cell(2, 
    1).Range.Text = "产品基本信息";
    newTable.Cell(2, 1).Range.Font.Color = 
    Word.WdColor.wdColorDarkBlue;//设置单元格内字体颜色
    //合并单元格
    newTable.Cell(2, 
    1).Merge(newTable.Cell(2, 3));
    WordApp.Selection.Cells.VerticalAlignment = 
    Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;

    //填充表格内容
    newTable.Cell(3, 
    1).Range.Text = "品牌名称:";
    newTable.Cell(3, 2).Range.Text = 
    BrandName;

    //纵向合并单元格
    newTable.Cell(3, 3).Select();//选中一行
    object 
    moveUnit = Word.WdUnits.wdLine;
    object moveCount = 5;
    object moveExtend = 
    Word.WdMovementType.wdExtend;
    WordApp.Selection.MoveDown(ref moveUnit, ref 
    moveCount, ref 
    moveExtend);
    WordApp.Selection.Cells.Merge();
    //插入图片
    string FileName = 
    Picture;//图片所在路径
    object LinkToFile = false;
    object SaveWithDocument = 
    true;
    object Anchor = 
    WordDoc.Application.Selection.Range;
    WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, 
    ref LinkToFile, ref SaveWithDocument, ref 
    Anchor);
    WordDoc.Application.ActiveDocument.InlineShapes[1].Width = 
    100f;//图片宽度

    WordDoc.Application.ActiveDocument.InlineShapes[1].Height = 
    100f;//图片高度
    //将图片设置为四周环绕型
    Word.Shape s = 
    WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();
    s.WrapFormat.Type 
    = Word.WdWrapType.wdWrapSquare;

    newTable.Cell(12, 1).Range.Text = 
    "产品特殊属性";
    newTable.Cell(12, 1).Merge(newTable.Cell(12, 
    3));
    //在表格中增加行
    WordDoc.Content.Tables[1].Rows.Add(ref 
    Nothing);

    WordDoc.Paragraphs.Last.Range.Text = "文档创建时间:" + 
    DateTime.Now.ToString();//“落款”
    WordDoc.Paragraphs.Last.Alignment = 
    Word.WdParagraphAlignment.wdAlignParagraphRight;


    //文件保存
    WordDoc.SaveAs(ref 
    filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref 
    Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref 
    Nothing, ref Nothing, ref Nothing, ref Nothing);
    WordDoc.Close(ref Nothing, 
    ref Nothing, ref Nothing);
    WordApp.Quit(ref Nothing, ref Nothing, ref 
    Nothing);
    message=name+"文档生成成功,以保存到C:CNSI下";
    }
    catch
    {
    message = 
    "文件导出异常!";
    }
    return message;
    }

    86.快速高效的文件加密
    /*
    using 
    System.IO;
    using System.Windows.Forms.Design;//加载System.Design.dll的.Net 
    API
    */
    private static int ka,kb,kc,kd;
    int[] 
    a={2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};
    int[] 
    b={3,3,3,5,5,3,3,3,5,3,5,3,7,3,11,7,11,3,5,3,3,3,7,5,5,3,7,3,11,13,3};
    int[] 
    c={3,5,7,5,7,11,13,19,17,29,19,31,17,41,11,19,13,47,29,53,59,67,29,41,43,71,31,73,23,23,101};
    int[] 
    d={5,7,11,13,17,17,19,29,43,43,47,47,59,61,61,67,71,71,73,79,89,101,101,103,107,107,109,109,127,149,151};

    private 
    static int niyuan(int m,int n)
    {
    int 
    a,b,c,d,t,yu,shang,mod;
    a=m;
    b=n;
    mod=a;
    c=0;
    d=1;
    while(b<0)
    b+=a;
    if(a%b==0 
    || b%2==0)
    return 
    0;
    while(b!=1)
    {
    t=a%b;
    shang=a/b;
    a=b;
    b=t;
    yu=c-shang*d;
    c=d;
    d=yu;
    }
    if(yu<0)
    yu+=mod;
    return 
    yu;
    }

    private static int GetDaysInMoths(int nMonths)
    {
    return 
    new DateTime(DateTime.Now.Year,nMonths).DaysInMonth;
    }

    private static 
    void init()
    {
    DateTime t2=new DateTime(1979,9,23);
    DateTime 
    t1=DateTime.Now;
    TimeSpan ts=t1-t2;
    Random rand=new 
    Random(ts.Days*8-55);
    UInt32 
    r=rand.NextDouble()*(GetDaysInMonths(t2.Month)));
    ka=a[r];
    kb=b[r];
    kc=c[r];
    kd=d[r];
    }

    private 
    class FolderDialog : FolderNameEditor
    {
    FolderNameEditor.FolderBrowser 
    fDialog = 
    new
    System.Windows.Forms.Design.FolderNameEditor.FolderBrowser();
    public 
    FolderDialog()
    {
    }
    public DialogResult DisplayDialog()
    {
    return 
    DisplayDialog("请选择一个文件夹");
    }

    public DialogResult DisplayDialog(string 
    description)
    {
    fDialog.Description = description;
    return 
    fDialog.ShowDialog();
    }
    public string Path
    {
    get
    {
    return 
    fDialog.DirectoryPath;
    }
    }
    ~FolderDialog()
    {
    fDialog.Dispose();
    }
    }

    FolderDialog 
    dlg = new FolderDialog();
    dlg.DisplayDialog();
    FolderDialog dlg2 = new 
    FolderDialog();
    dlg.DisplayDialog();
    if(dlg.ShowDialog()==DialogResult.OK)
    {
    if(Path.GetExtension(dlg.SelectedPath).ToLower()==".txt")
    {
    if(dlg2.ShowDialog()==DialogResult.OK 
    )
    {
    init();
    }
    }
    else
    {
    if(dlg2.ShowDialog()==DialogResult.OK 
    )
    {
    init();
    }
    }

    87.从CSV文件构造XML文档
    /*
    using 
    System.IO;
    using System.Xml.Linq;
    using System.Net;
    using 
    System.Text.RegularExpressions;
    */
    string[] 
    quotes=File.ReadLines(%%1);
    XElement stockQuotes=new XElement("Root",from 
    quote in quotes
    let fields=quote.Split(new 
    char[]{',','-'},StringSplitOption.RemoveEmptyEntries)
    select new 
    XElement("Company",fields[0].Trim()),
    new 
    XElement("LastPrice",fields[2].Trim()),
    new 
    XElement("Time",fields[1].Trim()),
    new 
    XElement("HighToday",fields[3].Trim()),
    stockQuotes.Save(%%2);

    88.从XML文档生成CSV文件
    /*
    using 
    System.IO;
    using System.Collections.Generic;
    using System.Linq;
    using 
    System.Text;
    using System.Xml.Linq;
    */
    XElement 
    black=XElement.Load(%%1);
    string file=
    (from elem in 
    black.Elements("Player")
    let statistics=elem.Element("Statistics")
    select 
    string.Format("{0},{1},{2},{3}",
    (string)statistics.Attribute("Name"),
    (string)statistics.Element("AverageAmountLost"),
    (string)statistics.Element("AverageAmountWon"),
    Environment.NewLine)),
    Aggregate(new 
    StringBuilder(),(builder,str)=>builder.Append(str),
    builder=>builder.ToString());
    FileInfo 
    f = new FileInfo(%%2);
    StreamWriter w = 
    f.CreateText();
    w.Write(file);
    w.Flush();
    w.Close();

    89.模拟键盘输入字符串
    //using 
    System.Windows.Forms;
    SendKeys.SendWait(%%1);

    90.提取PDF文件中的文本
    xpdf
    public 
    OpenFileDialog ofdlg = new OpenFileDialog();//打开文件对话框
    public string 
    filename;

    public 
    Form1()
    {
    InitializeComponent();
    }

    private void 
    button1_Click(object sender, EventArgs e)
    {
    ofdlg.Filter = 
    "pdf文件(*.pdf)|*.pdf";//选择pdf文件
    if (ofdlg.ShowDialog() == 
    DialogResult.OK)
    {
    filename = string.Format("{0}", 
    ofdlg.FileName);
    }
    }
    //传送打开文件对话框中得到的filename来做为外部程序的参数来做转化
    private 
    void button2_Click(object sender, EventArgs e)
    {
    Process p = new 
    Process();
    string path = "pdftotext.exe"; 
    //进程启用外部程序
    //这个exe我放在debug文件夹下面
    p.StartInfo.FileName = 
    path;
    p.StartInfo.Arguments = string.Format( filename + " 
    -");//很怪异的一行
    //参数“-”表示可以得到输出流
    p.StartInfo.UseShellExecute = 
    false;
    p.StartInfo.RedirectStandardInput = 
    true;
    p.StartInfo.RedirectStandardOutput = 
    true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.CreateNoWindow 
    = true;

    p.Start();
    string s = 
    p.StandardOutput.ReadToEnd();//得到pdf文档中的文本内容
    textBox1.Text = 
    s;
    p.Close();
    }
    }

    上面的程序运行后,如果是在Debug文件夹下的pdf文件就可以得到输出,可是如果在打开文件对话框中打开我桌面上的一个pdf如:@"d:\我的文档\test.pdf",输出就会是空,但是如果把上面那怪异的一行改为:
    C# 
    code
    p.StartInfo.Arguments = string.Format( @"d:\我的文档\test.pdf" + " 
    -");


    程序就又会得到输出。
    呵呵,谢谢楼上的兄台,下载的xpdf中xpdftotext.exe用到的配置文件xpdfrc需要手动配置,我如果把那些字体啊,什么的映射成绝对路径下的文件,就不会出现上面的问题,但是我把配置文件中的路径改成了相对路径,于是就出现了上面的问题了,看兄台能够很轻易的就运行成功,一定是做过很多代码的,这里还得劳烦兄台再给看一下,帮下忙,能遇到一个大神不容易,大神可不能吝啬啊,先谢过了哈

    91.操作内存映射文件
    /*
    using 
    System.Runtime.InteropServices;
    [DllImport("kernel32.dll")]
    public static 
    extern IntPtr CreateFileMapping(IntPtr hFile,
    IntPtr lpFileMappingAttributes, 
    uint flProtect,
    uint dwMaximumSizeHigh,
    uint dwMaximumSizeLow, string 
    lpName);

    [DllImport("kernel32.dll")]
    public static extern IntPtr 
    MapViewOfFile(IntPtr hFileMappingObject, uint
    dwDesiredAccess, uint 
    dwFileOffsetHigh, uint dwFileOffsetLow,
    IntPtr 
    dwNumberOfBytesToMap);

    [DllImport("kernel32.dll")]
    public static 
    extern bool UnmapViewOfFile(IntPtr 
    lpBaseAddress);

    [DllImport("kernel32.dll")]
    public static extern bool 
    CloseHandle(IntPtr hObject);

    [DllImport("kernel32.dll")]
    public static 
    extern IntPtr CreateFile(string lpFileName,
    int dwDesiredAccess, FileShare 
    dwShareMode, IntPtr securityAttrs,
    FileMode dwCreationDisposition, int 
    dwFlagsAndAttributes, IntPtr 
    hTemplateFile);

    [DllImport("kernel32.dll")]
    public static extern uint 
    GetFileSize(IntPtr hFile, IntPtr lpFileSizeHigh);

    public const int 
    GENERIC_READ = -2147483648; //0x80000000
    public const int GENERIC_WRITE = 
    0x40000000;
    public const int GENERIC_EXECUTE = 0x20000000;
    public const 
    int GENERIC_ALL = 0x10000000;
    public const int FILE_ATTRIBUTE_NORMAL = 
    0x80;
    public const int FILE_FLAG_SEQUENTIAL_SCAN = 0x8000000;
    public const 
    int INVALID_HANDLE_VALUE = -1;

    public const int PAGE_NOACCESS = 
    1;
    public const int PAGE_READONLY = 2;
    public const int PAGE_READWRITE = 
    4;

    public const int FILE_MAP_COPY = 1;
    public const int FILE_MAP_WRITE 
    = 2;
    public const int FILE_MAP_READ = 4;
    */
    IntPtr vFileHandle = 
    CreateFile(@"c:\temp\temp.txt",
    GENERIC_READ | GENERIC_WRITE, FileShare.Read 
    | FileShare.Write,
    IntPtr.Zero, FileMode.Open,
    FILE_ATTRIBUTE_NORMAL | 
    FILE_FLAG_SEQUENTIAL_SCAN, IntPtr.Zero);
    if (INVALID_HANDLE_VALUE != 
    (int)vFileHandle)
    {
    IntPtr vMappingHandle = 
    CreateFileMapping(
    vFileHandle, IntPtr.Zero, PAGE_READWRITE, 0, 0, 
    "~MappingTemp");
    if (vMappingHandle != IntPtr.Zero)
    {
    IntPtr vHead = 
    MapViewOfFile(vMappingHandle,
    FILE_MAP_COPY | FILE_MAP_READ | FILE_MAP_WRITE, 
    0, 0, IntPtr.Zero);
    if (vHead != IntPtr.Zero)
    {
    uint vSize = 
    GetFileSize(vFileHandle, IntPtr.Zero);
    for (int i = 0; i <= vSize / 2; 
    i++)
    {
    byte vTemp = Marshal.ReadByte((IntPtr)((int)vHead + 
    i));
    Marshal.WriteByte((IntPtr)((int)vHead + 
    i),
    Marshal.ReadByte((IntPtr)((int)vHead + vSize - i - 
    1)));
    Marshal.WriteByte((IntPtr)((int)vHead + vSize - i - 1), 
    vTemp);
    }
    UnmapViewOfFile(vHead);
    }
    CloseHandle(vMappingHandle);
    }
    CloseHandle(vFileHandle);
    }

    92.重定向windows控制台程序的输出信息
    //using 
    System.Diagnostics;
    delegate void dReadLine(string strLine);
    private void 
    excuteCommand(string strFile, string args, dReadLine 
    onReadLine)
    {
    System.Diagnostics.Process p = new Process();
    p.StartInfo 
    = new System.Diagnostics.ProcessStartInfo();
    p.StartInfo.FileName = 
    strFile;
    p.StartInfo.Arguments = args;
    p.StartInfo.WindowStyle = 
    System.Diagnostics.ProcessWindowStyle.Hidden;
    p.StartInfo.RedirectStandardOutput 
    = true;
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.CreateNoWindow = 
    true;
    p.Start();
    System.IO.StreamReader reader = 
    p.StandardOutput;//截取输出流
    string line = reader.ReadLine();//每次读取一行
    while 
    (!reader.EndOfStream)
    {
    onReadLine(line);
    line = 
    reader.ReadLine();
    }
    p.WaitForExit();
    }
    private void 
    PrintMessage(string strLine)
    {
    %%2 += strLine + " 
    ";
    }
    excuteCommand("cmd", " "+%%1, new 
    dReadLine(PrintMessage));

    //先读取文本中的命令假设为strCommand
    string 
    strCommand="ipconfig";
    string strRst=string.Empty;
    Process p = new 
    Process();
    p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.Arguments = "/c " 
    + strCommand;

    p.StartInfo.UseShellExecute = 
    false;
    //重定向标准输入
    //p.StartInfo.RedirectStandardInput = 
    false;
    //重定向标准输出
    p.StartInfo.RedirectStandardOutput = 
    true;
    //重定向错误输出
    p.StartInfo.RedirectStandardError = 
    false;
    //设置不显示窗口
    p.StartInfo.CreateNoWindow = 
    true;
    try
    {
    //启动进程
    p.Start();
    //停止3秒钟
    Thread.Sleep(3000);
    //如果进程结束
    //或者你可以等到结束再获取
    if 
    (p.HasExited)
    {

    //从输出流获取执行结果
    strRst = 
    p.StandardOutput.ReadToEnd();
    }
    else
    {
    p.Kill();
    }
    }
    catch 
    (Exception ex)
    {
    strRst = 
    "";
    }
    finally
    {
    p.Close();
    }
    //strRst即为运行后的结果,再将他写入另一个文本

    93.序列化
    using 
    System.Collections;
    using System.Text;

    namespace 
    SerializableTest
    {
    [Serializable]
    public class Book
    {
    public 
    Book()
    {
    alBookReader = new ArrayList();
    }

    public string 
    strBookName;

    [NonSerialized]
    public string strBookPwd;

    private 
    string _bookID;
    public string BookID
    {
    get { return _bookID; }
    set { 
    _bookID = value; }
    }

    public ArrayList alBookReader;

    private 
    string _bookPrice;
    public void SetBookPrice(string price)
    {
    _bookPrice 
    = price;
    }

    public void Write()
    {
    Console.WriteLine("Book ID:" + 
    BookID);
    Console.WriteLine("Book Name:" + 
    strBookName);
    Console.WriteLine("Book Password:" + 
    strBookPwd);
    Console.WriteLine("Book Price:" + 
    _bookPrice);
    Console.WriteLine("Book Reader:");
    for (int i = 0; i < 
    alBookReader.Count; 
    i++)
    {
    Console.WriteLine(alBookReader[i]);
    }
    }
    }
    }
    using 
    (FileStream fs = new FileStream(strFile, FileMode.Create))
    {
    Book book = 
    new Book();
    book.BookID = 
    "1";
    book.alBookReader.Add("gspring");
    book.alBookReader.Add("永春");
    book.strBookName 
    = "C#强化";
    book.strBookPwd = 
    "*****";
    book.SetBookPrice("50.00");
    BinarySerialize serialize = new 
    BinarySerialize();
    serialize.Serialize(book);
    }

    94.反序列化
    using 
    System.Collections;
    using System.Text;

    namespace 
    SerializableTest
    {
    [Serializable]
    public class Book
    {
    public 
    Book()
    {
    alBookReader = new ArrayList();
    }

    public string 
    strBookName;

    [NonSerialized]
    public string strBookPwd;

    private 
    string _bookID;
    public string BookID
    {
    get { return _bookID; }
    set { 
    _bookID = value; }
    }

    public ArrayList alBookReader;

    private 
    string _bookPrice;
    public void SetBookPrice(string price)
    {
    _bookPrice 
    = price;
    }

    public void Write()
    {
    Console.WriteLine("Book ID:" + 
    BookID);
    Console.WriteLine("Book Name:" + 
    strBookName);
    Console.WriteLine("Book Password:" + 
    strBookPwd);
    Console.WriteLine("Book Price:" + 
    _bookPrice);
    Console.WriteLine("Book Reader:");
    for (int i = 0; i < 
    alBookReader.Count; 
    i++)
    {
    Console.WriteLine(alBookReader[i]);
    }
    }
    }
    }
    Book 
    book;
    using (FileStream fs = new FileStream(strFile, 
    FileMode.Open))
    {
    BinaryFormatter formatter = new 
    BinaryFormatter();
    book = (Book)formatter.Deserialize(fs);
    }
    return 
    book;

    95.报表相关
    /*
    using 
    CrystalDecisions.CrystalReports.Engine;
    using 
    CrystalDecisions.Shared;
    */
    2、水晶报表的两种格式
    1)pull模式,不利用DataSet,直接从数据库中取出数据
    2) 
    push模式,使用DataSet,利用它进行数据的加载和处理等
    3. 
    水晶报表使用的库
    1)水晶报表的引擎(CREnging.dll),作用:合并数据,装换格式
    2)水晶报表设计器(CRDesigner.dll),作用:设计标题,插入数据等
    3)水晶报表查看控件(CRWebFormViewer.DLL)
    4)需要引入的命名空间
    using 
    CrystalDecisions.CrystalReports.Engine;
    using 
    CrystalDecisions.Shared;
    4、Pull模式下使用水晶报表
    1)创建rpt文件
    2)拖放CrystalReportViewer
    3)绑定
    5、读取水晶报表文件
    private 
    void ReadCRV(cryatalReportViewer crv)
    {
    openFileDialog dlg=new 
    OpenFileDialog();
    dlg.Title="打开水晶报表文件";
    dlg.Filter="水晶报表文件(*.rpt)|*.rpt|所有文件|*.*";
    if(dlg.showDialog()==DialogResult.OK)
    {
    crv.ReportSource=dlg.FileName;
    }
    }
    6. 
    B/S下读取报表的文件
    private void ReadCRV(cryatalReportViewer crv,File 
    file)
    {
    string 
    strName=file.PostedFile.FileName;
    if(strName.Trim()!="")
    {
    crv.ReportSource=strName
    Session["fileName"]=strName;
    }
    }
    在B/S中要防止数据源的丢失
    priavte 
    void Page_Load(object sender,System.EventArgs 
    e)
    {
    if(Session["fileName"]!=null)
    {
    crv.ReportSource=Session["fileName"].ToString();
    }
    }
    7. 
    假如直接从数据库中读取数据,采用PULL模式可能出现错误(登录的用户名和密码不对)
    private void 
    ReadCRV(CrystalReportViewer crv,CrystalReport cr)
    {
    ReportDocument 
    reportDoc=new 
    ReportDocument();
    reportDoc.Load(Server.MapPath(cr));//要加载的rpt文件的名字
    //解决登录的问题
    TableLogOnInfo 
    logonInfo = new TableLogOnInfo();
    foreach(Table tb in 
    ReportDoc.Database.Tables)
    {
    logonInfo=tb.LogOnInfo;
    logonInfo.ConnectionInfo.ServerName="(loacl)";
    logonInfo.ConnectionInfo.DatabaseName="Pubs";
    logonInfo.ConnectionInfo.UserId="sa";
    logonInfo.ConnectionInfo.Password="";
    tb.ApplyLogOnInfo(logonInfo);
    }
    crv.ReportSource=reportDoc;
    }
    8. 
    采用Push模式,直接在数据源读取
    private void BindReport(CrystalReportViewer 
    crv)
    {
    string 
    strProvider="Server=(local);DataBase=pubs;uid=sa;pwd=";
    CrystalReport cr=new 
    CrystalReport();
    DataSet ds=new DataSet();
    SqlConnection conn=new 
    SqlConnection(strProvider);
    conn.open();
    string strSql="select * from 
    jobs";
    SqlDataAdapter dap=new 
    SqlDataAdapter(strSql,conn);
    adp.Fill(ds,"jobs");
    cr.SetDataSource(ds);
    crv.ReportSource=cr;
    }
    9. 
    导出水晶报表的文件
    private void ExportCrv(CrystalReport 
    cr)
    {
    DiskFileDestionOptions dOpt=new 
    DiskFileDestionOptions();
    cr.ExportOptions.ExportDestinationType=ExportDestinationType.DiskFile();
    cr.ExportOptions.ExportFormatType= 
    ExportFormatType.PortableDocFormat;
    dOpt.DiskFileName="C:\output.pdf";
    cr.ExportOptions.DestinationOptions=dOpt;
    cr.Export();

    }
    private 
    void ExportCrv(CrystalReport cr,string strType,string 
    strPath)
    {
    DiskFileDestionOptions dOpt=new 
    DiskFileDestionOptions();
    cr.ExportOptions.ExportDestinationType=ExportDestinationType.DiskFile();
    switch(strType)
    {
    case 
    "RTF":
    cr.ExportOptions.ExportFormatType=ExportFormatType.RichText;
    dOpt.DiskFileName=strPath;
    break;
    case 
    "PDF":
    cr.ExportOptions.ExportFormatType=ExportFormatType.PortableDocFormat;
    dOpt.DiskFileName=strPath;
    break;
    case 
    "DOC":
    cr.ExportOptions.ExportFormatType=ExportFormatType.WordForWindows;
    dOpt.DiskFileName=strPath;
    break;
    case 
    "XLS":
    cr.ExportOptions.ExportFormatType=ExportFormatType.Excel;
    dOpt.DiskFileName=strPath;
    break;
    default;
    break;

    }
    cr.ExportOptions.DestinationOptions=dOpt;
    cr.Export();

    }
    10 
    B/S下水晶报表的打印
    priavte void PrintCRV(CrystalReport cr)
    {
    string 
    strPrinterName=@"printName";
    PageMargins 
    margins=cr.PrintOptions.PageMargins;
    margins.bottomMargin = 
    250;
    margins.leftMargin = 350;
    margins.rightMargin = 
    350;
    margins.topMargin = 
    450;
    cr.PrintOptions.ApplyPageMargins(margins);
    cr.PrintOptions.printerName=strPrinterName;
    cr.PrintToPrinter(1,false,0,0)//参数设置为0,表示打印所用页
    }

    96.全屏幕截取

    /*
    using 
    System.Drawing.Drawing2D;
    using System.Runtime.InteropServices;
    using 
    System.Collections;
    using System.Drawing.Imaging;
    using 
    System.Threading;
    */
    [DllImport("gdi32.dll")]
    private static extern int 
    BitBlt(IntPtr hdcDest,int nXDest,int nYDest,int nWidth,int nHeight,IntPtr 
    hdcSrc,int nXSrc,int nYSrc,UInt32 
    dwRop);
    //this.Hide();//如果你不想截取的图象中有此应用程序
    //Thread.Sleep(1000);
    Rectangle 
    rect = new Rectangle();
    rect = 
    Screen.GetWorkingArea(this);//获得当前屏幕的大小
    Graphics g = 
    this.CreateGraphics();
    //创建一个以当前屏幕为模板的图象
    Image myimage = new 
    Bitmap(rect.Width, rect.Height, g);
    //第二种得到全屏坐标的方法
    // Image myimage = new 
    Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,g);
    //创建以屏幕大小为标准的位图
    Graphics 
    gg = Graphics.FromImage(myimage);
    IntPtr dc = g.GetHdc();//得到屏幕的DC
    IntPtr 
    dcdc = gg.GetHdc();//得到Bitmap的DC
    BitBlt(dcdc, 0, 0, rect.Width, rect.Height, 
    dc, 0, 0, 
    13369376);
    //调用此API函数,实现屏幕捕获
    g.ReleaseHdc(dc);//释放掉屏幕的DC
    gg.ReleaseHdc(dcdc);//释放掉Bitmap的DC
    myimage.Save(Application.StartupPath 
    + @"\bob.jpg", 
    ImageFormat.Jpeg);//以JPG文件格式来保存
    this.Show();

    97.区域截屏
    /*
    using 
    System.Drawing.Drawing2D;
    using System.Runtime.InteropServices;
    using 
    System.Collections;
    using System.Drawing.Imaging;
    using 
    System.Threading;
    [DllImport("gdi32.dll")]
    public static extern IntPtr 
    CreateDC(
    string lpszDriver, // driver name
    string lpszDevice, // device 
    name
    string lpszOutput, // not used; should be NULL
    Int64 lpInitData // 
    optional printer data
    );

    [DllImport("gdi32.dll")]
    public static 
    extern IntPtr CreateCompatibleDC(
    IntPtr hdc // handle to 
    DC
    );

    [DllImport("gdi32.dll")]
    public static extern int 
    GetDeviceCaps(
    IntPtr hdc, // handle to DC
    GetDeviceCapsIndex nIndex // 
    index of capability
    );

    [DllImport("gdi32.dll")]
    public static 
    extern IntPtr CreateCompatibleBitmap(
    IntPtr hdc, // handle to DC
    int 
    nWidth, // width of bitmap, in pixels
    int nHeight // height of bitmap, in 
    pixels
    );

    [DllImport("gdi32.dll")]
    public static extern IntPtr 
    SelectObject(
    IntPtr hdc, // handle to DC
    IntPtr hgdiobj // handle to 
    object
    );

    [DllImport("gdi32.dll")]
    public static extern int 
    BitBlt(
    IntPtr hdcDest, // handle to destination DC
    int nXDest, // x-coord 
    of destination upper-left corner
    int nYDest, // y-coord of destination 
    upper-left corner
    int nWidth, // width of destination rectangle
    int 
    nHeight, // height of destination rectangle
    IntPtr hdcSrc, // handle to 
    source DC
    int nXSrc, // x-coordinate of source upper-left corner
    int 
    nYSrc, // y-coordinate of source upper-left corner
    UInt32 dwRop // raster 
    operation code
    );

    [DllImport("gdi32.dll")]
    public static extern int 
    DeleteDC(
    IntPtr hdc // handle to DC
    );
    */
    public static Bitmap 
    GetPartScreen(Point P1,Point P2,bool Full)
    {
    IntPtr 
    hscrdc,hmemdc;
    IntPtr hbitmap,holdbitmap;
    int 
    nx,ny,nx2,ny2;
    nx=ny=nx2=ny2=0;
    int nwidth, nheight;
    int xscrn, 
    yscrn;
    hscrdc = CreateDC("DISPLAY", null, null, 0);//创建DC句柄
    hmemdc = 
    CreateCompatibleDC(hscrdc);//创建一个内存DC
    xscrn = GetDeviceCaps(hscrdc, 
    GetDeviceCapsIndex.HORZRES);//获取屏幕宽度
    yscrn = GetDeviceCaps(hscrdc, 
    GetDeviceCapsIndex.VERTRES);//获取屏幕高度
    if(Full)//如果是截取整个屏幕
    {
    nx = 
    0;
    ny = 0;
    nx2 = xscrn;
    ny2 = yscrn;
    }
    else
    {
    nx = 
    P1.X;
    ny = P1.Y;
    nx2 =P2.X;
    ny2 =P2.Y;
    //检查数值合法性
    if(nx<0)nx = 
    0;
    if(ny<0)ny = 0;
    if(nx2>xscrn)nx2 = xscrn;
    if(ny2>yscrn)ny2 
    = yscrn;
    }
    nwidth = nx2 - nx;//截取范围的宽度
    nheight = ny2 - 
    ny;//截取范围的高度
    hbitmap = CreateCompatibleBitmap(hscrdc, nwidth, 
    nheight);//从内存DC复制到hbitmap句柄
    holdbitmap = SelectObject(hmemdc, 
    hbitmap);
    BitBlt(hmemdc, 0, 0, nwidth, nheight,hscrdc, nx, 
    ny,(UInt32)0xcc0020);
    hbitmap = SelectObject(hmemdc, 
    holdbitmap);
    DeleteDC(hscrdc);//删除用过的对象
    DeleteDC(hmemdc);//删除用过的对象
    return 
    Bitmap.FromHbitmap(hbitmap);//用Bitmap.FromHbitmap从hbitmap返回Bitmap
    }

    98.计算文件MD5值
    /*
    using 
    System.IO;
    using System.Security.Cryptography;
    */
    string path = 
    %%1;
    FileStream fs = new 
    FileStream(path,FileMode.Open,FileAccess.Read);
    MD5CryptoServiceProvider md5 
    = new MD5CryptoServiceProvider();
    byte [] md5byte = 
    md5.ComputeHash(fs);
    int i,j;
    StringBuilder sb = new 
    StringBuilder(16);
    foreach (byte b in md5byte)
    {
    i = 
    Convert.ToInt32(b);
    j = i >> 
    4;
    sb.Append(Convert.ToString(j,16));
    j = ((i << 4) & 0x00ff) 
    >> 4;
    sb.Append(Convert.ToString(j,16));
    }
    string 
    %%2=sb.ToString();

    99.计算获取文件夹中文件的MD5值
    /*
    using System.IO;
    using 
    System.Security.Cryptography;
    using System.Collections;
    */
    bool 
    b=false;
    string path = (%%2.LastIndexOf(Path.DirectorySeparatorChar) == 
    %%2.Length - 1) ? %%2 : %%2 + Path.DirectorySeparatorChar;
    string parent = 
    Path.GetDirectoryName(%%1);
    Directory.CreateDirectory(path + 
    Path.GetFileName(%%1));
    DirectoryInfo dir = new 
    DirectoryInfo((%%1.LastIndexOf(Path.DirectorySeparatorChar) == %%1.Length - 1) ? 
    %%1 : %%1 + Path.DirectorySeparatorChar);
    FileSystemInfo[] fileArr = 
    dir.GetFileSystemInfos();
    Queue<FileSystemInfo> Folders = new 
    Queue<FileSystemInfo>(dir.GetFileSystemInfos());
    while (Folders.Count 
    > 0)
    {
    FileSystemInfo tmp = Folders.Dequeue();
    FileInfo f = tmp as 
    FileInfo;
    if (b && f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    Directory.CreateDirectory(d.FullName.Replace((parent.LastIndexOf(Path.DirectorySeparatorChar) 
    == parent.Length - 1) ? parent : parent + Path.DirectorySeparatorChar, 
    path));
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    else
    {
    FileStream 
    fs = new 
    FileStream(f,FileMode.Open,FileAccess.Read);
    MD5CryptoServiceProvider md5 = 
    new MD5CryptoServiceProvider();
    byte [] md5byte = md5.ComputeHash(fs);
    int 
    i,j;
    StringBuilder sb = new StringBuilder(16);
    foreach (byte b in 
    md5byte)
    {
    i = Convert.ToInt32(b);
    j = i >> 
    4;
    sb.Append(Convert.ToString(j,16));
    j = ((i << 4) & 0x00ff) 
    >> 4;
    sb.Append(Convert.ToString(j,16));
    }
    string 
    %%3=sb.ToString();
    }
    }

    100.复制一个目录下所有文件到一个文件夹中
    /*
    using 
    System.IO;
    using System.Collections;
    */
    string path = 
    (%%2.LastIndexOf(Path.DirectorySeparatorChar) == %%2.Length - 1) ? %%2 : 
    %%2+Path.DirectorySeparatorChar;
    string parent = 
    Path.GetDirectoryName(%%1);
    Directory.CreateDirectory(path + 
    Path.GetFileName(%%1));
    DirectoryInfo dir = new 
    DirectoryInfo((%%1.LastIndexOf(Path.DirectorySeparatorChar) == %%1.Length - 1) ? 
    %%1 : %%1 + Path.DirectorySeparatorChar);
    FileSystemInfo[] fileArr = 
    dir.GetFileSystemInfos();
    Queue<FileSystemInfo> Folders = new 
    Queue<FileSystemInfo>(dir.GetFileSystemInfos());
    while 
    (Folders.Count>0)
    {
    FileSystemInfo tmp = Folders.Dequeue();
    FileInfo 
    f = tmp as FileInfo;
    if (f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    else
    {
    f.CopyTo(path+f.Name);
    }
    }

    101.移动一个目录下所有文件到一个文件夹中
    /*
    using 
    System.IO;
    using System.Collections;
    */
    string path = 
    (%%2.LastIndexOf(Path.DirectorySeparatorChar) == %%2.Length - 1) ? %%2 : 
    %%2+Path.DirectorySeparatorChar;
    string parent = 
    Path.GetDirectoryName(%%1);
    Directory.CreateDirectory(path + 
    Path.GetFileName(%%1));
    DirectoryInfo dir = new 
    DirectoryInfo((%%1.LastIndexOf(Path.DirectorySeparatorChar) == %%1.Length - 1) ? 
    %%1 : %%1 + Path.DirectorySeparatorChar);
    FileSystemInfo[] fileArr = 
    dir.GetFileSystemInfos();
    Queue<FileSystemInfo> Folders = new 
    Queue<FileSystemInfo>(dir.GetFileSystemInfos());
    while 
    (Folders.Count>0)
    {
    FileSystemInfo tmp = Folders.Dequeue();
    FileInfo 
    f = tmp as FileInfo;
    if (f == null)
    {
    DirectoryInfo d = tmp as 
    DirectoryInfo;
    foreach (FileSystemInfo fi in 
    d.GetFileSystemInfos())
    {
    Folders.Enqueue(fi);
    }
    }
    else
    {
    f.MoveTo(path+f.Name);
    }
    }

    102.文件RSA高级加密
    /*
    using 
    System.IO;
    using System.Security.Cryptography;
    private 
    RSACryptoServiceProvider _rsa;
    */
    FileStream fin=new 
    FileStream(%%1,FileMode.Open,FileAccess.Read);
    FileStream fout=new 
    FileStream(%%2,FileMode.OpenOrCreate,FileAccess.Write);
    byte[] readBuffer=new 
    byte[128];
    fin.Read(readBuffer,0,readBuffer.Length);
    byte[] 
    encryptedBuffer=_rsa.Encrypt(readBuffer,true);
    _rsa.Clear();

    103.计算文件大小
    /*
    using 
    System.IO;
    private const long KB=1024;
    private const long 
    MB=1024*KB;
    private const long GB=1024*MB;
    */
    FileInfo fi = new 
    FileInfo(%%1);
    long filesize= fi.Length;
    string 
    showsize;
    if(filesize>=GB)
    showsize.format("%0.2f 
    GB",(double)filesize/GB);
    else if(filesize>=MB)
    showsize.format("%0.2f 
    MB",(double)filesize/MB);
    else if(filesize>=KB)
    showsize.format("%0.2f 
    KB",(double)filesize/KB);
    else if(filesize>1)
    showsize.format("%ld 
    Bytes",filesize);
    else
    showsize="1 Byte";
    string 
    %%2=showsize;

    104.计算文件夹的大小
    /*
    using System.IO;
    private const 
    long KB=1024;
    private const long MB=1024*KB;
    private const long 
    GB=1024*MB;
    */
    private static long FolderFileSize(string 
    path)
    {
    long size = 0;
    try
    {
    FileInfo [] files = (new 
    DirectoryInfo(path)).GetFiles();
    foreach(FileInfo file in files)
    {
    size 
    += file.Length;
    }
    }
    catch(Exception 
    ex)
    {
    MessageBox.Show(ex.Message);
    }
    return 
    size;
    }

    private static long FolderSize(string path)
    {
    long Fsize 
    = 0;
    try
    {
    Fsize = FolderFileSize(path);
    DirectoryInfo [] folders = 
    (new DirectoryInfo(path)).GetDirectories();
    foreach(DirectoryInfo folder in 
    folders)
    Fsize += FolderSize(folder.FullName);
    }
    catch(Exception 
    ex)
    {
    MessageBox.Show(ex.Message);
    }
    return Fsize;
    }
    long 
    filesize= FolderSize(%%1);
    string 
    showsize;
    if(filesize>=GB)
    showsize.format("%0.2f 
    GB",(double)filesize/GB);
    else if(filesize>=MB)
    showsize.format("%0.2f 
    MB",(double)filesize/MB);
    else if(filesize>=KB)
    showsize.format("%0.2f 
    KB",(double)filesize/KB);
    else if(filesize>1)
    showsize.format("%ld 
    Bytes",filesize);
    else
    showsize="1 Byte";
    string 
    %%2=showsize;

    105.快速获得当前程序的驱动器、路径、文件名和扩展名
    //using 
    System.IO;
    DirectoryInfo dires= new 
    DirectoryInfo(Application.StartupPath);
    string strQDQ = null;//驱动器
    strQDQ 
    = dires.Root.ToString();
    string strPath 
    =Application.ExecutablePath;//路径

    string FName = null;//文件名
    string 
    FNameExt = null;//扩展名
    FileInfo FileIno = new FileInfo(strPath);
    FName = 
    FileIno.Name;
    FNameExt = 
    FileIno.Extension;

    106.磁盘剩余空间计算
    /*
    using 
    System.Runtime.InteropServices;
    //第一种
    [DllImport("kernel32")]
    public 
    static extern bool GetDiskFreeSpaceEx(string Path,out long
    bytesAvail, out 
    long bytesOnDisk, out long freeBytesOnDisk);

    long bytesAvail, 
    bytesOnDisk,freeBytesOnDisk,lpTotalNumberOfClusters;
    //lpRootPathName 
    String,不包括卷名的一个磁盘根路径
    //lpSectorsPerCluster 
    Long,用于装载一个簇内扇区数的变量
    //lpBytesPerSector 
    Long,用于装载一个扇区内字节数的变量
    //lpNumberOfFreeClusters 
    Long,用于装载磁盘上剩余簇数的变量
    //lpTtoalNumberOfClusters 
    Long,用于装载磁盘上总簇数的变量
    */
    string tempImagePath = 
    Application.StartupPath;//取出应用安装的目录。
    GetDiskFreeSpaceEx(tempImagePath, out 
    bytesAvail, out bytesOnDisk, out freeBytesOnDisk);
    textBox1.Text = 
    (freeBytesOnDisk/1024/1024).ToString();

    //第二种 
    引用System.Management
    //using System.Management;
    ManagementClass diskClass = 
    new ManagementClass("Win32_LogicalDisk");
    ManagementObjectCollection 
    disks=diskClass.GetInstances();
    System.UInt64 
    space=UInt64.MinValue;
    foreach(ManagementObject disk in 
    disks)
    {
    if((disk["Name"]).ToString() == "C:")
    space = 
    (System.UInt64)(disk["FreeSpace"]);
    }
    //第三种 framework 中已经有类了, 不需要调用 
    API
    //using System.IO;
    long x = new DriveInfo(%%1).AvailableFreeSpace; 
    //"C"
    string showsize;
    if (x >= GB)
    showsize.format("%0.2f GB", 
    (double)x / GB);
    else if (x >= MB)
    showsize.format("%0.2f MB", 
    (double)x / MB);
    else if (x >= KB)
    showsize.format("%0.2f KB", 
    (double)x / KB);
    else if (x > 1)
    showsize.format("%ld Bytes", 
    x);
    else
    showsize = "1 Byte";
    return 
    showsize;

    107.获取当前程序进程ID
    //using System.Diagnostics;
    int %%1 = 
    Process.GetCurrentProcess().Id;

    108.全盘搜索文件
    /*
    using 
    System.Text;
    using System.IO;
    */
    string strFileName;
    public string 
    StrFileName{get { return strFileName; }set { strFileName = value; }}
    delegate 
    void Temp(string fileName);
    delegate void ShowProgressDelegate(string 
    fileName, string filePath, IList<IlsitFileFindModleClass> 
    objIlist);
    IList<IlsitFileFindModleClass> objIlist;
    public void 
    GetFoldersPath(){
    if (GridSearch.InvokeRequired == 
    false){}
    else{
    objIlist = new 
    List<IlsitFileFindModleClass>();
    string retStr = null;
    DriveInfo[] 
    allDrives = DriveInfo.GetDrives();//检索计算机上的所有逻辑驱动器的驱动器名称
    foreach (DriveInfo 
    driPath in 
    allDrives){//循环输出各分区的信息
    FileSeach(driPath.Name);
    }
    }
    }
    public 
    void GetFoldersPath(string root){
    if (GridSearch.InvokeRequired == false) { 
    }
    else { objIlist = new List<IlsitFileFindModleClass>(); 
    FileSeach(root); }
    }
    public void FileSeach(string root){
    string 
    strFileNameTemp = StrFileName;
    Stack<string> dirs = new 
    Stack<string>(20);
    if 
    (!System.IO.Directory.Exists(root))
    return;
    dirs.Push(root);
    while 
    (dirs.Count > 0){
    string currentDir = dirs.Pop();
    string[] 
    subDirs;
    try{
    subDirs = 
    System.IO.Directory.GetDirectories(currentDir);
    }
    catch 
    (UnauthorizedAccessException e) { continue; }
    catch 
    (System.IO.DirectoryNotFoundException e) { continue; }
    Temp temp=new 
    Temp(Testll);
    label2.Invoke(temp, new object[] { currentDir 
    });
    try{
    string[] filesTemp = System.IO.Directory.GetFiles(currentDir, 
    StrFileName + ".*");
    if (filesTemp.Length > 0){
    objIlist.Add(new 
    IlsitFileFindModleClass(strFileNameTemp, currentDir + "\\" + strFileNameTemp + 
    ".*"));
    ShowProgressDelegate objTemp = new 
    ShowProgressDelegate(test);
    BeginInvoke(objTemp, new object[] { 
    strFileNameTemp, currentDir + "\\" + strFileNameTemp + ".*", objIlist 
    });
    continue;
    }
    }
    catch (UnauthorizedAccessException e) { continue; 
    }
    catch (System.IO.DirectoryNotFoundException e) { continue; }
    foreach 
    (string str in subDirs)
    dirs.Push(str);
    }
    }
    StrFileName 
    =%%1;
    MethodInvoker mi = new 
    MethodInvoker(GetFoldersPath);
    mi.BeginInvoke(null, null);

    转载于:https://www.cnblogs.com/dawn-cn/p/4263921.html

    展开全文
  • "this.className='style3'"   class = "style3" >    19.打印页面   align= "center" >  class =content href= "javascript:doPrint();" >打印本稿</a></div>    20.可以直接写html语言  ...
  • 200+JS功能 实例

    2019-10-04 08:19:48
    onmouseout="this.className='style3'" class="style3"> 19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div> 20.可以直接写html语言 document.write(""); 21....
  • 模拟面试面试题汇总 

    千次阅读 2021-04-27 18:45:17
    集合有两个父接口,一个Collection,一个Map,而Collection有两个子接口,一个List,一个Set,List有两个常见的实现类ArrayList,LinkedList, Set有两个常见的实现类HashSet,TreeSet,Map有两个常见的实现类HashMap,...
  • 最全面、最详细web前端面试题及答案总结

    万次阅读 多人点赞 2021-02-01 09:34:00
    就⽐如下⾯的选择器,它不存在内联样式,所以A=0,不存在id选择器B=0,存在⼀个选择器C=1,存在三个标签选择器 D=3,那么最终计算结果为: {0, 0, 1 ,3} 按照这个结算⽅式,下⾯的计算结果为: {0, 1, 0, 0} 我们的⽐...
  • 200多个JS小技巧

    千次阅读 2013-05-10 10:07:04
    onmouseout="this.className='style3'" class="style3">   19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div>   20.可以直接写html语言 document....
  • C#文件操作大全

    2020-10-24 22:00:50
    1.创建文件夹 //using System.IO;...3.删除文件 //using System.IO; File.Delete(%%1); 4.删除文件夹 //using System.IO; Directory.Delete(%%1); 5.删除一个目录下所有的文件夹 //using System.IO; foreac
  • 多个js技能代码

    千次阅读 2012-02-01 11:48:17
    1.文本框核心题目 onBlur:当落空输入核心后产生该事务 onFocus:当输入获得核心后,产生该文件 Onchange:当文字&#20540;改变时,产生该事务 On:当文字加亮后,产生该文件 人不然则靠他生来就拥有一切,而是靠...
  • onmouseout="this.className='style3'" class="style3"> 19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div> 20.可以直接写html语言 document.write(""); ...
  • onmouseout="this.className='style3'" class="style3"> 19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div> 20.可以直接写html语言 document.write(""); ...
  • js技巧收集(200多个)

    2019-10-01 07:27:21
    onmouseout="this.className='style3'" class="style3"> 19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div> 20.可以直接写html语言 document.write(""); 21...
  • onmouseout="this.className='style3'" class="style3"> 19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div> 20.可以直接写html语言 document.write(""); 21...
  • onmouseout="this.className='style3'" class="style3"> 19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div> 20.可以直接写html语言 document.write(""); 21...
  • js的各种事件

    2019-09-26 05:39:32
    35.页内跳转 <a href="#1">1</a> <a href="#2">2</a> <a href="#3">3</a> <a href="#4">4</a> <a href="#5">5</a> <a href="#6">6</a> <a href="#7">7</a> <a name="1">dfdf</a> <a name="2">dfdf</a>// 36.两个...
  • onmouseout="this.className='style3'" class="style3"> 19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div> 20.可以直接写html语言 document.write(""); ...
  • 1.创建文件夹 //using  System.IO; Directory.CreateDirectory(%%1); 2.创建文件 //using  ...3.删除文件 //using  System.IO; File.Delete(%%1); 4.删除文件夹 //using  System.IO; D
  • (转)常用的js代码

    2019-08-09 07:04:55
    onmouseout="this.className='style3'" class="style3"> 19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div> 20.可以直接写html语言 document.write(""); ...
  • JS代码整理

    2019-07-26 21:40:14
    onmouseout="this.className='style3'" class="style3"> 19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div> 20.可以直接写html语言 document.write(""); 21...
  • js常用

    2019-03-05 18:39:00
    ="this.className='style3'" class ="style3"> 19 .打印页面 <div align="center"><a class =content href="javascript:doPrint();">打印本稿</a></div> 20 .可以直接写html语言 document.write( "" ); 21...
  • onmouseout=”this.className=’style3′”class=”style3″> 19.打印页面 ”center” amp;>amp; amp;>amp; amp;>amp; lt;a class=contenthref=”javascript:doPrint();”>打印本稿 amp;>amp; ...
  • onmouseout=”this.className=’style3′”class=”style3″> 19.打印页面 ”center”$amp;>amp;$lt;a class=contenthref=”javascript:doPrint();”>打印本稿$amp;>amp;$lt;/div> 20.可以直接写html...
  • js大全

    2018-03-24 17:13:59
    onmouseout="this.className='style3'" class="style3"> 19.打印页面 <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div> 20.可以直接写html语言 ...
  • 231个web前端常用的javascript特效分享

    千次阅读 2018-08-03 09:03:55
    onmouseout=”this.className=’style3′”class=”style3″> 19.打印页面 ”center”amp;>amp;amp;>amp;lt;a class=contenthref=”javascript:doPrint();”>打印本稿;>amp;amp;>amp;lt;/div> ...

空空如也

空空如也

1 2 3 4 5 ... 16
收藏数 317
精华内容 126
关键字:

7-3 定义classname接口,设计类company,实现获取类名称的功能 分数 10 全屏浏览题目 作者 强彦 单位 太原理工大学 定义一个classname接口,接口中只有一个抽象方法getclassname();设计一个类company,该类实现接口classname中的方法getclassname(),功能是获取该类的类名称

友情链接: DVP_C_EN_20120309.rar