- 902 名前:デフォルトの名無しさん mailto:sage [2007/05/08(火) 16:12:47 ]
- >>899
import java.io.*; public class Expand { public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println("java Expand infile outfile"); return; } int expand = 8; // TAB width BufferedReader in = null; BufferedWriter out = null; try { in = new BufferedReader(new FileReader(args[0])); out = new BufferedWriter(new FileWriter(args[1])); String s; while ((s = in.readLine()) != null) { StringBuilder sb = new StringBuilder(s); int index = 0; while ((index = sb.indexOf("\t", index)) != -1) { sb.setCharAt(index, ' '); for (int i = index % expand + 1; i < expand; i++) sb.insert(index, ' '); } out.write(sb.toString()); out.newLine(); } } finally { if (in != null) in.close(); if (out != null) out.close(); } } }
|

|