[Java Swing tycoon] Java Common Files, pictures, audio = = = Generic Tool class

Source: Internet
Author: User

/** * This class of tool classes for working with Project resources * <p> * Note that project resources must be placed in the project catalog SRC, or you can apply the project external resources to indicate the absolute path */public class Fileutil {// The project file must be in the SRC directory under one of the following 3 subfolders private static final string file = "file/";//store ordinary file private static final string IMAGE = "images/"; Store picture file private static final String audio = "music/";//store audio file private static final hashmap<string, string> MAP = new Hashmap<string, string> (), Static {map.put ("file", file); Map.put ("image", image); Map.put ("audio", audio);} /** * Returns the URL address of the resource file * @param type resource file types, including files, pictures, and audio * @param path resource file paths to external files with an absolute path (such as c:/me.jpg) if an internal file is a file name (such as: me.jpg)    * The URL address of the @return resource file */public static URL GetURL (string type, string path) {string dir = Map.get (type);    Return Urlclassloader.getsystemclassloader (). getresource (dir + path);    }//Gets the file resource public static "file GetFile (String path) {URL url = GetURL (" file ", path);    if (url = = null) {return null;    } return new File (Url.getfile ()); }//Get Picture resource public static image GetImage (StRing path) {URL url = GetURL ("image", path);    if (url = = null) {return null;    } return Toolkit.getdefaulttoolkit (). GetImage (URL);    }//Get audio resource public static AudioClip Getaudio (String path) {URL url = GetURL ("audio", path);    if (url = = null) {return null;    } return Applet.newaudioclip (URL); }    }

The usage is simple and clear. Need a friend to pick up.

[Java Swing tycoon] Java Common Files, pictures, audio = = = Generic Tool class

Related Article

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.