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.