无需言 做自己 业 ,精于勤 荒于嬉.

JAVA基础 22.Properties

发表日期:2022-08-05 16:34:13 | 来源: | 分类:JAVA基础

      示例1
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

public class PropertiesDemo01 {

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

      File file = new File("D:"+File.separator+"javaDemo.txt");
      
      Properties pro = new Properties();
      
      pro.setProperty("name", "张三");
      pro.setProperty("age", "22");
      pro.setProperty("sex", "男");
      
      System.out.println(pro.getProperty("name"));
      System.out.println(pro.getProperty("age"));
      System.out.println(pro.getProperty("sex"));
      
      //#保存至文件
      OutputStream out = new FileOutputStream(file);
      //pro.save(out , "这里是注释");//save方法过时了
      //pro.store(out, "这里是注释");
      //pro.storeToXML(out, "这里是注释", "GBK");
      pro.storeToXML(out, "这里是注释");//encoding 默认是UTF-8
      
      //#从文件中读取
      InputStream in = new FileInputStream(file);
      pro.loadFromXML(in);
      System.out.println(pro.getProperty("name"));
      System.out.println(pro.getProperty("age"));
      System.out.println(pro.getProperty("sex"));
   }

}

阅读全文 »

JAVA基础 21.Map

发表日期:2022-08-05 16:33:10 | 来源: | 分类:JAVA基础

      示例1
import java.util.HashMap;
import java.util.Map;



public class MapDemo01 {

   public static void main(String[] args) {
      // TODO 自动生成的方法存根
      
      Map<String, String> map = new HashMap<String, String>();
      map.put("name", "zhangsan");
      map.put("work", "techer");
   }

}
      示例2
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;


public class HashMapDemo01 {

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

      HashMap<String, String> map = new HashMap<String, String>();//HashMap  => TreeMap = sort

      map.put("百度", "www.baidu.com");
      map.put("腾讯", "www.qq.com");
      map.put("网易", "www.163.com");
      if (map.containsKey("百度")) {

         System.out.println(map.get("百度"));

      }

      Set<String>  keys = map.keySet();//Collection<String>  keys = map.values();

      Iterator<String> iterator = keys.iterator();

      while (iterator.hasNext()) {

         String str = iterator.next();

         System.out.print(str+"\\");

      }

   }

}

阅读全文 »

JAVA基础 20.List

发表日期:2022-08-05 16:31:29 | 来源: | 分类:JAVA基础

      示例1
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


public class ArrayListDemo01 {

   /**
    * @param args
    */
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      
      List<String> allList = new ArrayList<String>(); 
      allList.add("hello");
      allList.add("world");
      allList.add(1,"my");//在第二个位置上添加内容
      System.out.println(allList);
      
      Collection<String> allCollection  = new ArrayList<String>();

      allCollection.add("hello");
      allCollection.add("world");
      //allCollection.add(1," ");//错误i
      System.out.println(allCollection);
      
      allList.addAll(allCollection);//可以指定位置
      System.out.println(allList);

      allList.remove("world");//根据内容删除  但是只删除第一个
      
      System.out.println(allList);
      allList.remove(0);//根据内容删除  但是只删除第一个
      System.out.println(allList);
      System.out.println("allList的长度为:"+allList.size());
      
      for (int i = 0; i < allList.size(); i++) {
         System.out.print(allList.get(i)+"、");
      }
      
      String arr[] = allList.toArray(new String[]{});//将list 对象转换为 array 对象
      
   }

}
      示例2
import java.util.Set;
import java.util.TreeSet;

class Person implements Comparable<Person> {
    private int age;
    private String name;

    public Person(String name, int age) {
        setName(name);
        setAge(age);
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int compareTo(Person person) {
        if (this.age > person.age) {
            return 1;
        } else if (this.age < person.age) {
            return -1;
        } else {
            //return 0;
            return this.name.compareTo(person.name);
        }
    }

    public String toString() {
        return "姓名:" + getName() + "  年龄:" + getAge();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + age;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Person other = (Person) obj;
        if (age != other.age)
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        return true;
    }

}


public class TreeSetDemo {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Set<Person> treeSet = new TreeSet<Person>();
        treeSet.add(new Person("张三", 30));
        treeSet.add(new Person("李四", 40));
        treeSet.add(new Person("王二", 20));
        treeSet.add(new Person("赵六", 60));
        treeSet.add(new Person("麻子", 30));
        treeSet.add(new Person("李四", 13));
        treeSet.add(new Person("赵六", 60));
        System.out.println(treeSet);
        //return 0;
        //[姓名:李四  年龄:13, 姓名:王二  年龄:20, 姓名:张三  年龄:30, 姓名:李四  年龄:40, 姓名:赵六  年龄:60]
        /**
         * 麻子 30 不见了
         * 李四 13、40
         * 赵六去重复了
         */

        //[姓名:李四  年龄:13, 姓名:王二  年龄:20, 姓名:张三  年龄:30, 姓名:麻子  年龄:30, 姓名:李四  年龄:40, 姓名:赵六  年龄:60]
        //赵六去重复了只有赵六去重复了

        //[姓名:李四  年龄:13, 姓名:王二  年龄:20, 姓名:张三  年龄:30, 姓名:麻子  年龄:30, 姓名:李四  年龄:40, 姓名:赵六  年龄:60]
    }

}

阅读全文 »

JAVA基础 19.Charset

发表日期:2022-08-05 16:24:36 | 来源: | 分类:JAVA基础

      示例1
public class CharsetDemo01 {

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

        System.out.println(System.getProperty("file.encoding"));//GBK


    }

}

阅读全文 »

JAVA基础 18.zip

发表日期:2022-08-05 16:22:18 | 来源: | 分类:JAVA基础

      示例1
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;


public class ZipDemo01 {

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

      File file = new File("d:"+File.separator+"test.txt");
      
      File zipFile = new File("d:"+File.separator+"test.zip");
      
      FileInputStream fis = new FileInputStream(file);
      
      FileOutputStream fos = new FileOutputStream(zipFile);
      
      ZipOutputStream zos = new ZipOutputStream(fos);
      
      zos.setComment("这里是注释");
      
      ZipEntry zEntry = new ZipEntry(file.getName());
      
      zos.putNextEntry(zEntry);
      
      int temp = 0;
      
      while ((temp=fis.read())!=-1) {
         
         zos.write(temp);
         
      }
      
      
      zos.finish() ;
      zos.close();

   }

   private static Object Charset(String string) {
      // TODO Auto-generated method stub
      return null;
   }

}
      示例2
/**
 * Created by Administrator on 2016/4/5.
 */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

public class ZipUtils {

   public static void zip(ArrayList<String> src, String dest) throws IOException {

      ZipOutputStream out = null;
      try {
         File outFile = new File(dest);// 源文件或者目录
         out = new ZipOutputStream(new FileOutputStream(outFile));

         for (int i = 0; i < src.size(); i++) {
            File fileOrDirectory = new File(src.get(i));// 压缩文件路径
            zipFileOrDirectory(out, fileOrDirectory, "");
         }
         
      } catch (IOException ex) {
         ex.printStackTrace();
      } finally {
         // 关闭输出流
         if (out != null) {
            try {
               out.close();
            } catch (IOException ex) {
               ex.printStackTrace();
            }
         }
      }
   }

   public static void zip(String src, String dest) throws IOException {
      // 提供了一个数据项压缩成一个ZIP归档输出流
      ZipOutputStream out = null;
      try {

         File outFile = new File(dest);// 源文件或者目录
         File fileOrDirectory = new File(src);// 压缩文件路径
         out = new ZipOutputStream(new FileOutputStream(outFile));
         // 如果此文件是一个文件,否则为false。
         if (fileOrDirectory.isFile()) {
            zipFileOrDirectory(out, fileOrDirectory, "");
         } else {// 返回一个文件或空阵列。
            File[] entries = fileOrDirectory.listFiles();
            for (int i = 0; i < entries.length; i++) {
               // 递归压缩,更新curPaths
               zipFileOrDirectory(out, entries[i], "");
            }
         }

      } catch (IOException ex) {
         ex.printStackTrace();
      } finally {
         // 关闭输出流
         if (out != null) {
            try {
               out.close();
            } catch (IOException ex) {
               ex.printStackTrace();
            }
         }
      }
   }

   private static void zipFileOrDirectory(ZipOutputStream out,
         File fileOrDirectory, String curPath) throws IOException {
      // 从文件中读取字节的输入流
      FileInputStream in = null;
      try {
         // 如果此文件是一个目录,否则返回false。
         if (!fileOrDirectory.isDirectory()) {
            // 压缩文件
            byte[] buffer = new byte[4096];
            int bytes_read;
            in = new FileInputStream(fileOrDirectory);
            // 实例代表一个条目内的ZIP归档
            ZipEntry entry = new ZipEntry(curPath
                  + fileOrDirectory.getName());
            // 条目的信息写入底层流
            out.putNextEntry(entry);
            while ((bytes_read = in.read(buffer)) != -1) {
               out.write(buffer, 0, bytes_read);
            }
            out.closeEntry();
         } else {
            // 压缩目录
            File[] entries = fileOrDirectory.listFiles();
            for (int i = 0; i < entries.length; i++) {
               // 递归压缩,更新curPaths
               zipFileOrDirectory(out, entries[i], curPath
                     + fileOrDirectory.getName() + "/");
            }
         }
      } catch (IOException ex) {
         ex.printStackTrace();
         // throw ex;
      } finally {
         if (in != null) {
            try {
               in.close();
            } catch (IOException ex) {
               ex.printStackTrace();
            }
         }
      }
   }

   @SuppressWarnings("unchecked")
   public static void unzip(String zipFileName, String outputDirectory)
         throws IOException {
      ZipFile zipFile = null;
      try {
         zipFile = new ZipFile(zipFileName);
         Enumeration e = zipFile.entries();
         ZipEntry zipEntry = null;
         File dest = new File(outputDirectory);
         dest.mkdirs();
         while (e.hasMoreElements()) {
            zipEntry = (ZipEntry) e.nextElement();
            String entryName = zipEntry.getName();
            InputStream in = null;
            FileOutputStream out = null;
            try {
               if (zipEntry.isDirectory()) {
                  String name = zipEntry.getName();
                  name = name.substring(0, name.length() - 1);
                  File f = new File(outputDirectory + File.separator
                        + name);
                  f.mkdirs();
               } else {
                  int index = entryName.lastIndexOf("\\");
                  if (index != -1) {
                     File df = new File(outputDirectory + File.separator
                           + entryName.substring(0, index));
                     df.mkdirs();
                  }
                  index = entryName.lastIndexOf("/");
                  if (index != -1) {
                     File df = new File(outputDirectory + File.separator
                           + entryName.substring(0, index));
                     df.mkdirs();
                  }
                  File f = new File(outputDirectory + File.separator
                        + zipEntry.getName());
                  // f.createNewFile();
                  in = zipFile.getInputStream(zipEntry);
                  out = new FileOutputStream(f);
                  int c;
                  byte[] by = new byte[1024];
                  while ((c = in.read(by)) != -1) {
                     out.write(by, 0, c);
                  }
                  out.flush();
               }
            } catch (IOException ex) {
               ex.printStackTrace();
               throw new IOException("解压失败:" + ex.toString());
            } finally {
               if (in != null) {
                  try {
                     in.close();
                  } catch (IOException ex) {
                  }
               }
               if (out != null) {
                  try {
                     out.close();
                  } catch (IOException ex) {
                  }
               }
            }
         }
      } catch (IOException ex) {
         ex.printStackTrace();
         throw new IOException("解压失败:" + ex.toString());
      } finally {
         if (zipFile != null) {
            try {
               zipFile.close();
            } catch (IOException ex) {
            }
         }
      }
   }
}

/*
 * Activity调用 package com.comc; import java.io.IOException; import
 * com.zipUtil.ZipUtil; import android.app.Activity; import android.os.Bundle;
 * public class IZipActivity extends Activity {
 * 
 * 
 * @Override public void onCreate(Bundle savedInstanceState) {
 * super.onCreate(savedInstanceState); setContentView(R.layout.main); try {
 * ZipUtil.zip("/data/data/com.comc/databases",
 * "/data/data/com.comc/databases.zip");
 * ZipUtil.unzip("/data/data/com.comc/databases.zip",
 * "/data/data/com.comc/databases"); } catch (IOException e) {
 * e.printStackTrace(); } }
 * 
 * }
 */
      示例3
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class Demo {

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

        ArrayList<String> fileListsList = new ArrayList<String>();
        fileListsList.add("D:/zip/device-2016-03-26-195134.png");
        fileListsList.add("D:/demo/hyasset/config.xml");
        fileListsList.add("D:/demo.txt");
        fileListsList.add("D:/demosvn/YCCitizen/build/intermediates/dex-cache/");

        try {
            ZipUtils.zip(fileListsList, "D:/ziped/abc.zip");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

      /*
      try {
         ZipUtils.zip("D:/zip/", "D:/ziped/abc.zip");
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      */

    }

}

阅读全文 »

JAVA基础 15.DataOutputStream

发表日期:2022-08-05 16:20:31 | 来源: | 分类:JAVA基础

      示例1
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


public class OutputDemo01 {

   /**
    * @param args
    * @throws IOException 
    */
   public static void main(String[] args) throws IOException {
      // TODO Auto-generated method stub
      File file = new File("d:"+File.separator+"test.txt");
      
      FileOutputStream os = new FileOutputStream(file);

      DataOutputStream dos = new DataOutputStream(os);
      
      int arg = 123;
      
      dos.writeInt(arg);
      
   }

}

阅读全文 »

JAVA基础 14.Scanner

发表日期:2022-08-05 16:19:27 | 来源: | 分类:JAVA基础

      示例1
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;


public class ScannerDemo01 {

   /**
    * @param args
    * @throws FileNotFoundException 
    */
   public static void main(String[] args) throws FileNotFoundException {
      // TODO Auto-generated method stub
      
      File file = new File("d:"+File.separator+"test.txt");
      
      Scanner scanner = new Scanner(file);
      /*
      String string = scanner.next();
      
      System.out.println(string);
      */
      while (scanner.hasNext()) {
         String string = (String) scanner.next();
         System.out.println(string);
      }
   }

}

阅读全文 »

JAVA基础 13.BufferedReader

发表日期:2022-08-05 16:17:46 | 来源: | 分类:JAVA基础

      示例1
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class ReaderDemo01 {

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub

        File file = new File("d:" + File.separator + "OutputStreamDemo.txt");
        FileReader fr = new FileReader(file);
        BufferedReader br = new BufferedReader(fr);
        String str = null;
        while ((str = br.readLine()) != null) {
            System.out.println(str);
        }
        fr.close();
        br.close();
      /*
      FileReader fReader = null;
      try {
         fReader = new FileReader(file);
      } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      
      BufferedReader bReader = new BufferedReader(fReader);
      
      try {
         System.out.print(bReader.readLine());
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      */

    }

}
      示例2
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;


public class ReaderDemo02 {

   /**
    * @param args
    * @throws IOException 
    */
   public static void main(String[] args) throws IOException {
      // TODO Auto-generated method stub
      InputStream is = System.in;//字节流
      InputStreamReader isr = new InputStreamReader(is);//转换为字符流
      BufferedReader br = new BufferedReader(isr);

      System.out.println("请输入内容");
      
      String str = null;
      while ((str = br.readLine())!=null) {
         if ("exit".equals(str)) {
            break;
         }
         System.out.println(str);
      }
      is.close();
      isr.close();
      br.close();
      System.out.println("bye!");
      
      /*
      BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
      
      String string = null;
      
      System.out.println("请输入内容");
      
      try {
         string = bReader.readLine();
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      
      System.out.println("输入内容:"+string);
      */
   }
}
      示例3
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class ExecDemo01 {

   /**
    * @param args
    * @throws IOException 
    */
   public static void main(String[] args) throws IOException {
      // TODO Auto-generated method stub
      
      int i = 0 ;
      int j = 0 ;
      
      BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
      
      String string = null;
      
      System.out.println("请输入第一个数字:");
      
      string = bReader.readLine();
      
      i = Integer.parseInt(string);

      System.out.println("请输入第二个数字:");

      string = bReader.readLine();
      
      j = Integer.parseInt(string);
      
      System.out.println(i+"+"+j+"="+(i+j));
      
      

   }

}

阅读全文 »

JAVA基础 12.InputStreamReader和OutputStreamWriter

发表日期:2022-08-05 16:13:02 | 来源: | 分类:JAVA基础

      示例1
package stream;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class InputStreamReaderDemo {

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

      File file = new File("D:"+File.separator+"123.txt");
      FileInputStream stream = new FileInputStream(file);
      InputStreamReader reader = new InputStreamReader(stream);
      char c[] = new char[1024];
      int length = reader.read(c);
      System.out.println(new String(c,0,length));
      stream.close();
      reader.close();
   }

}
      示例2
package stream;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class OutputStreamWriterDemo {

   /**
    * @param args
    * @throws IOException 
    */
   public static void main(String[] args) throws IOException {
      // TODO Auto-generated method stub
      File file = new File("D:"+File.separator+"123.txt");
      FileOutputStream stream = new FileOutputStream(file);
      OutputStreamWriter writer = new OutputStreamWriter(stream);
      
      writer.write("测试一下3。");
      writer.close();
      stream.close();
   }

}

阅读全文 »

JAVA基础 10.RandomAccessFile

发表日期:2022-08-05 16:09:05 | 来源: | 分类:JAVA基础

      示例1
package File;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;

public class RandomAccessFileDemo {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        File file = new File("D:" + File.separator + "RandomAccessFile.txt");
        //两种写法均可
        //RandomAccessFile rFile = new RandomAccessFile("D:"+File.separator+"test.txt", "rw");
        RandomAccessFile rFile = new RandomAccessFile(file, "rw");
        String string = "abcdefg我去这是什么情况?";
        ;

        rFile.write(string.getBytes());//写入中文会乱码
        rFile.close();

        write();
        read();
    }

    private static void read() {
        // TODO Auto-generated method stub

        File file = new File("d:" + File.separator + "123.txt");

        RandomAccessFile rFile = null;
        try {
            rFile = new RandomAccessFile(file, "r");

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            byte c[] = new byte[(int) rFile.length()];
            rFile.read(c);
            System.out.println(new String(c));

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

    public static void write() {

        File file = new File("d:" + File.separator + "123.txt");

        RandomAccessFile rFile = null;
        try {
            rFile = new RandomAccessFile(file, "rw");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        String name = "zhangsan";
        int age = 30;
        try {
            rFile.writeInt(age);
//       rFile.writeBytes(name);
            rFile.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

阅读全文 »

JAVA基础 9.FileReader和FileWriter

发表日期:2022-08-05 15:57:36 | 来源: | 分类:JAVA基础

      示例1
package File;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class FileReaderDemo {

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

      File file = new File("D:"+File.separator+"FileWriterDemo.txt");
      FileReader fileReader = new FileReader(file);

      char[] c = new char[1024];
      int length = fileReader.read(c);

      //int length = (int)file.length();其实获取文件大小本该没有错,可是却错了,后面是方格格占位符,为什么呢?如果是汉字会占用2个字节而这里却是以字符读取的。多了一倍

      System.out.println(new String(c , 0, length));
      fileReader.close();

   }

}
      示例2
package File;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class FileWriterDemo {

   /**
    * @param args
    * @throws IOException 
    */
   public static void main(String[] args) throws IOException {
      // TODO Auto-generated method stub
      File file = new File("D:"+File.separator+"FileWriterDemo.txt");
      
      
      FileWriter fWriter = new FileWriter(file,false);
      String string = "踩踩踩踩踩";
      fWriter.write(string);
      fWriter.close();
   }

}

阅读全文 »

JAVA基础 17.TimerTask

发表日期:2022-08-05 15:20:57 | 来源: | 分类:JAVA基础

      示例1
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;

public class MyTask extends TimerTask {//必须继承TimerTask
   
   public void run(){
      
      System.out.println(new SimpleDateFormat("yyyy年MM月dd日 HH点mm分ss秒").format(new Date()));
   }
   
   
}
      示例2
import java.util.Timer;


public class Task {

   public static void main(String[] args) {
      Timer timer = new Timer();
      MyTask myTask = new MyTask();
      timer.schedule(myTask, 1000, 2000);
      

   }

}

阅读全文 »

idea小技巧 语法错误之间跳转

发表日期:2022-01-11 21:53:30 | 来源: | 分类:idea小技巧

按 F2/Shift+F2 在突出显示的语法错误之间跳转。

按 Ctrl+t+向上箭头/Ctrl+Alt+向上箭头Al 在错误消息或搜索结果之间跳转。

要跳过警告,请右键单击验证侧栏/标记栏并选择仅转到高优先级问题。


阅读全文 »

idea小技巧 快速查看类或方法的文档

发表日期:2022-01-11 21:52:53 | 来源: | 分类:idea小技巧

要快速查看插入符号处的类或方法的文档,请按 Ctrl+Q(查看 | 快速文档)。

image.png

阅读全文 »

idea小技巧 使用最近的搜索历史

发表日期:2022-01-11 21:51:42 | 来源: | 分类:idea小技巧

在文件中搜索文本字符串时,使用最近的搜索历史。按 Ctrl+F 打开搜索窗格,然后按 Alt+向下箭头显示最近条目列表。

image.png

阅读全文 »

idea小技巧 Ctrl+Alt+Shift+D

发表日期:2022-01-11 21:47:55 | 来源: | 分类:idea小技巧

如果您的项目处于版本控制之下,您可以构建一个 UML 图来反映您的本地更改并可视化修改后的组件之间的关系。

按 Ctrl+Alt+Shift+D 并选择必要的更改列表来构建图表。双击图表上的节点以查看差异对话框中的更改。

image.png

阅读全文 »

idea小技巧 Shift 两次

发表日期:2022-01-11 21:47:07 | 来源: | 分类:idea小技巧

在 Search Everywhere(Shift 两次)窗口的搜索字段中输入“/”以搜索设置列表、它们的选项和插件。

您还可以搜索在您正在搜索的 URL 映射部分之前输入“/”的 URL 映射。

image.png

阅读全文 »

idea小技巧 在列模式下选择多个片段

发表日期:2022-01-11 21:45:42 | 来源: | 分类:idea小技巧

要在列模式下选择多个片段 Alt+Shift+Insert,请按住 Ctrl+Alt+Shift(在 Windows 和 Linux 上)/⌘⌥⇧(在 macOS 上),然后拖动鼠标:

image.png

阅读全文 »

idea小技巧 SQL 文件运行查询

发表日期:2022-01-11 21:38:17 | 来源: | 分类:idea小技巧

双击 SQL 文件以在 IDE 中打开它。要从此文件运行查询,请调用意图操作(对于 macOS,Option + Enter,对于 Windows 和 Linux,Alt+Enter)并选择在控制台中运行查询。在 Sessions 列表中,选择现有控制台或创建一个新控制台。

请注意,新的查询控制台意味着与数据源的新连接。

image.png

阅读全文 »

idea小技巧 Alt+Enter

发表日期:2022-01-11 21:36:43 | 来源: | 分类:idea小技巧

在编辑器中按 Alt+Enter 可修复突出显示的错误或警告、改进或优化代码结构。

对于某些意图操作,您可以通过按 Ctrl+Shift+I(查看 | 快速定义)打开预览。

image.png

阅读全文 »

全部博文(1589)
集速网 copyRight © 2015-2025 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。