Android Open Source - ObdCommandsTest Output To File Handler






From Project

Back to project page ObdCommandsTest.

License

The source code is released under:

GNU General Public License

If you think the Android project ObdCommandsTest listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.kantil.app.commandstest.util;
/*from www.j  a  va2  s  .  c o  m*/
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import android.content.Context;
import android.os.Environment;

import com.kantil.app.commandstest.R;
import com.kantil.app.commandstest.command.CommandsEnum;

public class OutputToFileHandler {
  public static final String FILEDIR = Environment
      .getExternalStorageDirectory() + "/CT/";
  public static final String TABLEFILE = FILEDIR + "table";

  public static void cleanFile(Context context) {
    new File(FILEDIR).mkdirs();
    File tableFile = new File(TABLEFILE);
    if (!tableFile.exists()) {
      tableFile.delete();
    }
    try {
      tableFile.createNewFile();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    try {
      // BufferedWriter for performance, true to set append to file flag
      BufferedWriter buf = new BufferedWriter(new FileWriter(tableFile,
          true));
      buf.append(context.getString(R.string.description) + " - "
          + context.getString(R.string.code) + " - "
          + context.getString(R.string.databytes) + " - "
          + context.getString(R.string.min) + " - "
          + context.getString(R.string.max) + " - "
          + context.getString(R.string.unit) + " - "
          + context.getString(R.string.formula) + " - "
          + context.getString(R.string.result));
      buf.newLine();
      buf.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

  public static void insertRow(CommandsEnum c, String result) {
    new File(FILEDIR).mkdirs();
    File logFile = new File(TABLEFILE);
    try {
      // BufferedWriter for performance, true to set append to file flag
      BufferedWriter buf = new BufferedWriter(new FileWriter(logFile,
          true));
      buf.append(c.getDescription() + " - " + c.getCode() + " - "
          + c.getDataBytes() + " - " + c.getMin() + " - "
          + c.getMax() + " - " + c.getUnit() + " - " + c.getFormula()
          + " - " + result);
      buf.newLine();
      buf.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}




Java Source Code List

com.kantil.app.commandstest.activity.MainActivity.java
com.kantil.app.commandstest.asyncTask.RunCommandsTask.java
com.kantil.app.commandstest.command.CommandsEnum.java
com.kantil.app.commandstest.command.ObdCommand.java
com.kantil.app.commandstest.util.Logger.java
com.kantil.app.commandstest.util.OutputToFileHandler.java