package com.chenyang.nse.bussiness.engine.infa.powercenter961.pubtool;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.List;

public class TxtFileUtil {
   public void modifyTxtFile(String path, List<String> para) throws Exception {
      FileOutputStream out = new FileOutputStream(path, false);
      out.write((new String("")).getBytes());
      out.close();
      File filename = new File(path);
      StringBuffer sb = new StringBuffer();
      sb.append("[Global]\r\n");

      for(int i = 0; i < para.size(); ++i) {
         sb.append((String)para.get(i) + "\r\n");
      }

      RandomAccessFile mm = null;

      try {
         mm = new RandomAccessFile(filename, "rw");
         mm.writeBytes(sb.toString());
      } catch (IOException e) {
         e.printStackTrace();
      } finally {
         if (mm != null) {
            try {
               mm.close();
            } catch (IOException e) {
               e.printStackTrace();
            }
         }

      }

   }

   public boolean deleteFile(String path) {
      Boolean flag = false;
      File file = new File(path);
      if (file.isFile() && file.exists()) {
         file.delete();
         flag = true;
      }

      return flag;
   }
}
