2011-11-26 39 views

回答

0

從傳感器/ src目錄/ AEXP /傳感器/ SensorMonitor.java Android SDK中的樣本中發現:

這是你如何創建文件:

private PrintWriter captureFile; 

    File captureFileName = new File("/sdcard", "capture.csv"); 
     captureStateText = "Capture: "+captureFileName.getAbsolutePath(); 
     try { 
      captureFile = new PrintWriter(new FileWriter(captureFileName, false)); 
     } catch(IOException ex) { 
      Log.e(LOG_TAG, ex.getMessage(), ex); 
      captureStateText = "Capture: "+ex.getMessage(); 
     } 

這是你如何寫入文件:

if(captureFile != null) { 
      for(int i = 0 ; i < sensorEvent.values.length ; ++i) { 
       if(i > 0) 
        captureFile.print(","); 
       captureFile.print(Float.toString(sensorEvent.values[i])); 
      } 
      captureFile.println(); 
    } 
} 

最後關閉文件:

 captureFile.close();