Let's Format Css Documents
每次想参考一些好看网站的时候,打开css文档都是一行的,琢磨了下就自己写了块短短的代码,各路Java大神别笑我呀。^_^
复制粘贴控制台的输出就好了。(瞬间觉得跟上大神的脚步了←_←)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | package sortingAlgorithm; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author xzh */ public class test { public static void main(String[] args){ try { FileInputStream fis = new FileInputStream( "./style.css" ); InputStreamReader insr = new InputStreamReader(fis, "utf-8" ); BufferedReader bufr = new BufferedReader(insr); String oneLine = "" ; String tmp; while ((tmp=bufr.readLine())!= null ){ oneLine += tmp; } String result = "" ; for ( int i= 0 ;i<oneLine.length();i++){ char ch = oneLine.charAt(i); switch (ch){ case '{' : result += "{\n\t" ; break ; case '}' : result += "\n}\n" ; break ; case ';' : if (oneLine.charAt(i+ 1 )!= '}' ){ result += ";\n\t" ; } else { result += ";\n" ; } break ; default : result += ch; } } System.out.println(result); } catch (FileNotFoundException | UnsupportedEncodingException ex) { Logger.getLogger(test. class .getName()).log(Level.SEVERE, null , ex); } catch (IOException ex) { Logger.getLogger(test. class .getName()).log(Level.SEVERE, null , ex); } } } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步