pmpeiomanager.java

来自「自己建立的项目」· Java 代码 · 共 40 行

JAVA
40
字号
package com.swtSample.text;

import java.io.*;

/**
 * This class handles loading and saving files
 */
public class PmpeIoManager {
  /**
   * Gets a file (loads it) from the filesystem
   * 
   * @param filename the full path of the file
   * @return String
   * @throws IOException if file cannot be loaded
   */
  public static String getFile(String filename) throws IOException {
    InputStream in = new BufferedInputStream(new FileInputStream(filename));
    StringBuffer buf = new StringBuffer();
    int c;
    while ((c = in.read()) != -1) {
      buf.append((char) c);
    }
    return buf.toString();
  }

  /**
   * Saves a file
   * 
   * @param filename the full path of the file to save
   * @param data the data to save
   * @throws IOException if file cannot be saved
   */
  public static void saveFile(String filename, byte[] data) throws IOException {
    File outputFile = new File(filename);
    FileOutputStream out = new FileOutputStream(outputFile);
    out.write(data);
    out.close();
  }
}

⌨️ 快捷键说明

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