Search for icons in a folder to generate Json and CSS files

Source: Internet
Author: User

You will never walk alone.

After talking nonsense, um... because I wanted to add a large number of icons, I had to write css on my own? Of course, this is too annoying .. Programmers should be lazy .. So I wrote something automatically generated ~.~

Let's try again

JSONArray array = StringBuffer cssStrBuf = String iconPath = "common/icon/" String iconCssPath = "../icon /";Declare Variables

The following is how to read the icon files under the folder and save the json and css formats.

JSONObject object = File file = (! Object = object. put ("name" object. put ("thumb", iconPath + file. getParentFile (). getName () + "/" + object. put ("url", iconPath + file. getParentFile (). getName () + "/" + object. put ("size", file. length () + "B" cssStrBuf. append (". "+ file. getName (). substring (0, file. getName (). lastIndexOf (". ") +" {background-image: url ("+ iconCssPath + file. getName () + ")! Important;} "} (file. isDirectory () {String [] filelist = (I = 0; I <filelist. length; I ++ File readfile = File (filepath ++ (! Readfile. isDirectory () {object = object. put ("name" object. put ("thumb", iconPath + readfile. getParentFile (). getName () + "/" + object. put ("url", iconPath + readfile. getParentFile (). getName () + "/" + object. put ("size", readfile. length () + "B" String fileName = readfile. getName (). substring (0, readfile. getName (). lastIndexOf (". "cssStrBuf. append (". "+ fileName +" {background-image: url ("+ iconCssPath + readfile. getNa Me () + ")! Important;} "} (readfile. isDirectory () {readfile (filepath + File. separatorChar + }}Readfile

After reading the above code... It is nothing more than reading files. Very simple .. So there are no annotations.
This is also the last file to be written, although the Internet is already flooded

File dirFile = (! BufferedWriter bw1 = BufferedWriter (}}Write files

The json and css files are formatted. Original format directly generated without line breaks

"Images" "name": "bug.png" "thumb": "common/icon/bug/bug.png" "url": "common/icon/bug/bug.png" "size ": "774B" "name": "bug_add.png" "thumb": "common/icon/bug/bug_add.png" "url": "common/icon/bug/bug_add.png" "size ": "806B" "name": "bug_delete.png" "thumb": "common/icon/bug/bug_delete.png" "url": "common/icon/bug/bug_delete.png" "size ": "836B" "name": "bug_edit.png" "thumb": "common/icon/bug/bug_edit.png" "url": "common/icon/bug/bug_edit.png" "size ": "873B" "name": "bug_error.png" "thumb": "common/icon/bug/bug_error.png" "url": "common/icon/bug/bug_error.png" "size ": "841B" "name": "bug_go.png" "thumb": "common/icon/bug/bug_go.png" "url": "common/icon/bug/bug_go.png" "size ": "831B" "name": "bug_link.png" "thumb": "common/icon/bug/bug_link.png" "url": "common/icon/bug/bug_link.png" "size ": "847B "}Json background-image: url (../icon/bug.png )! Background-image: url (../icon/bug_add.png )! Background-image: url (../icon/bug_delete.png )! Background-image: url (../icon/bug_edit.png )! Background-image: url (../icon/bug_error.png )! Background-image: url (../icon/bug_go.png )! Background-image: url (../icon/bug_link.png )! }Css

To close the job, keep a record and share your work (although this is a bad thing.

 

 

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.