⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exercise16_4.java

📁 java程序设计导论(daniel liang著) 所有偶数课后习题答案
💻 JAVA
字号:
/**
 * Convert Java source code from the next-line brace style to the
 * end-of-line brace style. Invoke the program with
 * java Exercise16_6 Test.java
 * to convert the Java source file Test.java into the end-of-line
 * brace style.
 *
 * 5/18/01
 */
import java.util.*;
import java.io.*;

public class Exercise16_4 {
  static BufferedReader input;
  static BufferedWriter output;
  static StringBuffer buffer = new StringBuffer();
  static String lineSeparator =	(String)java.security.
    AccessController.doPrivileged(
    new sun.security.action.GetPropertyAction("line.separator"));
  static String filename = null;

  /**Main method*/
  public static void main(String[] args) {
    try {
      filename = args[0];
      input = new BufferedReader(new FileReader(filename));

      input = new BufferedReader(new FileReader(filename));
      format();
      output = new BufferedWriter(new FileWriter(filename));
      output.write(buffer.toString());
      output.close();
    }
    catch (Exception ex) {
    }
  }

  public static void format() {
   try {
      String line;
      buffer = new StringBuffer();

      boolean firstLine = true;

      while ((line = input.readLine()) != null) {
        if ((line.trim().length() > 0) && (line.trim().charAt(0) == '{')) {
          buffer.append(" {");

          String s = line.replace('{', ' ');
          if (s.trim().length() > 0) {
            buffer.append(lineSeparator);
            buffer.append(s);
            System.out.println("Alert: " + filename + " has stuff after {");
          }
        }
        else {
          if (firstLine)
            firstLine = false;
          else
            buffer.append(lineSeparator);

          buffer.append(line);
        }
      }
    }
    catch (Exception ex) {
      System.out.println(ex);
    }
    finally {
      try {
        input.close();
      }
      catch (Exception ex) {
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -