]> Pileus Git - ~andy/csm213a-hw/blob - syc/src/com/example/sycapp/FileLogger.java
Add Android app from Yue
[~andy/csm213a-hw] / syc / src / com / example / sycapp / FileLogger.java
1 package com.example.sycapp;
2
3 import java.io.File;
4 import java.io.FileOutputStream;
5 import java.util.Vector;
6
7 import android.os.Environment;
8
9 public class FileLogger {
10         private String  fileName  = "logFile.txt";
11         private boolean logEnable = true;
12         
13         FileLogger(){
14                 
15         }
16         
17         public void setEnable(boolean bool){
18                 logEnable = bool;
19         }
20         
21         public void setNewFile(String newFileName){
22                 fileName = newFileName;
23                 Util.debug("[F#0]"+fileName);
24         }
25         
26         public String getFileName(){
27                 return fileName;
28         }
29         
30         public void writeExternal(Vector<SerialData> sData){
31                 //if(!logEnable) return;
32                 try{
33                         File myFile = new File(Environment
34                             .getExternalStorageDirectory(), fileName);
35
36                         //Util.debug("[F#1]"+fileName);
37                     //if (!myFile.exists())
38                         //myFile.createNewFile();
39                     FileOutputStream fex;
40                     fex = new FileOutputStream(myFile,true);
41                 for (int i = 0; i < sData.size(); i++){
42                         SerialData data = sData.get(i);
43                     fex.write(("[Node "+Integer.toString(data.devID)+"] "+data.timeStamp()+"\n").getBytes()) ;
44                 }
45                     fex.flush();
46                     fex.close();
47                 }catch(Exception e){
48                         Util.debug("M#7"+e.toString());
49                 }
50         }
51 }