匿名 #6544(2008/06/21 20:06 GMT) [ Java ] Rating0/0=0.00
一番のりを狙って書きました。起動パラメータに与えられたJavaのソースファイルからコメントを削除し、".out" 拡張子つきのファイルに書き込みます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import java.util.regex.*; import java.io.*; public class Decomment { static final Pattern COMMENT1 = Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL); static final Pattern COMMENT2 = Pattern.compile("//.*"); public static void main(String[] args) throws IOException { for (String name : args) { BufferedReader r = new BufferedReader(new FileReader(name)); FileWriter w = new FileWriter(name + ".out"); StringBuilder sb = new StringBuilder(); String line; while ((line = r.readLine()) != null) { sb.append(line).append(System.getProperty("line.separator")); } String s1 = COMMENT1.matcher(sb).replaceAll(""); String result = COMMENT2.matcher(s1).replaceAll(""); w.write(result); w.close(); } } }
Rating0/0=0.00-0+
1 reply [ reply ]
匿名
#6544()
[
Java
]
Rating0/0=0.00
一番のりを狙って書きました。起動パラメータに与えられたJavaのソースファイルからコメントを削除し、".out" 拡張子つきのファイルに書き込みます。
Rating0/0=0.00-0+
1 reply [ reply ]