Third-party jar packages: examples of Use

Source: Internet
Author: User


Third-party jar packages:

* What is a third party?
* First party: Oracle
* Second party: developers themselves
* Third party: In addition to Oracle and developers themselves
*
* What is a jar package?
* is the framework of some special file format, which contains a bunch of source code of bytecode file information, import into the project can use the function of the jar package
*
* What are the well-known jar packages?
* The United States has a well-known Software Foundation Apache (Apache), website: www.apache.org/
* It maintains a lot of well-known frameworks, such as: Structs,lucence,solr,activemq, have,hbase,hadoop,commons ... Wait more than 350.
*
* Some common tool classes are available in Commons:
such as
* Commons-io, operations and IO stream related content
* Commons-lang
* Commons-collection
* COMMONS-DBCP
* ....
*
* How to use jar package?
* 1. Create a folder in your project with the name generally written in Lib
* 2. Copy the corresponding jar package to the folder
* 3. Right-Select Build path, add to build path, the referenced reference is available
*
* Using the tool class in: Org.apache.commons.io.FileUtils;
* Steps to use:
* 1. Import Package Imports Org.apache.commons.io.FileUtils;
* 2. No need to create objects, all static methods
* 3. Common static methods:

* 3.1 Public Static voidwritestringtofile (file file, string data, String charsetname), writing string to the specified file* 3.2 Public Staticstring readfiletostring (file file, String charsetname); Specifies that the encoding table reads the contents* 3.3 Public Static voidcopyFile (Files srcfile, file destfile);* 3.4 Public Static voidcopydirectory (file srcdir, file destfile); Copy the contents of the folder* 3.5 Public Static voidcopydirectorytodirectory (file srcdir, file destfile), copy entire folder to new folder* 3.6 Public Static voidforcedelete (file file); Delete Files* 3.7 Public Static voidDeleteDirectory (File Dirflie); Delete a folder

* Note the point:
* General expiration method, not recommended, may be a security risk

 Public classDemo09commonsio { Public Static voidMain (string[] args)throwsIOException {//1.writeStringToFile (file file, string data, String charsetname);//writes a string to the specified file//Fileutils.writestringtofile (New File ("Test01.txt"), "Helloio flow Hello");//expired, not recommended//Fileutils.writestringtofile (New File ("Test01.txt"), "brush my drip card!", "GBK");//2. Read the contents of the file//String data = fileutils.readfiletostring (new File ("Test01.txt"));//expired, not recommended//String data = fileutils.readfiletostring (new File ("Test01.txt"), "GBK");//System.out.println (data);//3. Copying Files//file Srcfile = new file ("C:\\users\\sszz\\desktop\\aaa\\file02.txt");//file DestFile = new file ("C:\\users\\sszz\\desktop\\file02.txt");//fileutils.copyfile (Srcfile, destfile);//4. Copying folders//file Srcdir = new file ("C:\\users\\sszz\\desktop\\aaa");//file DestDir = new file ("c:\\users\\sszz\\desktop\\bbb");//fileutils.copydirectory (Srcdir, destDir);//Copy the contents of the folder to the new file//fileutils.copydirectorytodirectory (Srcdir, destDir);//copy an entire folder to a new folder//5. deleting files//file Srcfile = new file ("C:\\users\\sszz\\desktop\\file02.txt");//Fileutils.forcedelete (srcfile);//6 Deleting a folder//file DestDir = new file ("c:\\users\\sszz\\desktop\\bbb");//fileutils.deletedirectory (destDir);method ();//method2 ();}/*** This method has expired, please do not use, please use: method2*/@Deprecated Public Static voidmethod () {method2 ();}

Third-party jar packages: examples of Use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.