Пример #1
0
  /**
   * Writes configuration.
   *
   * @param config configuration String
   * @param writeType write type
   * @param configType configuration type
   * @throws IOException thrown when read fails
   */
  private static void writeConfig(String config, WriteReadType writeType, String fileName)
      throws IOException {

    File directory = new File(writeType.getDirectory());
    File file = new File(writeType.getDirectory() + fileName);

    if (!directory.exists()) {
      directory.mkdirs();
      Saga.info("Creating " + directory + " directory.");
    }

    if (!file.exists()) {
      file.createNewFile();
      Saga.info("Creating " + file + " file.");
    }

    BufferedWriter out = new BufferedWriter(new FileWriter(file));
    out.write(config);
    out.close();
  }
Пример #2
0
  /**
   * Reads configuration.
   *
   * @param writeType write type
   * @param configType configuration type
   * @throws IOException thrown when read fails
   */
  private static String readConfig(WriteReadType writeType, String fileName) throws IOException {

    // Add directory if missing:
    File directory = new File(writeType.getDirectory());
    if (!directory.exists()) {
      directory.mkdirs();
      Saga.info("Creating " + directory + " directory.");
    }

    File file = new File(writeType.getDirectory() + fileName);
    int ch;
    StringBuffer strContent = new StringBuffer("");
    FileInputStream fin = null;
    fin = new FileInputStream(file);
    while ((ch = fin.read()) != -1) {
      strContent.append((char) ch);
    }
    fin.close();

    return strContent.toString();
  }