안드로이드 초짜입니다.
이 문제로 벌써 10시간동안 고생했는데 계속 오류만 나고 답을 못찾겠습니다.

가속도 값(변수)이 변할때 마다 그 값을 txt파일에 기록하고 싶은데요
근데 지금 코딩한 방법으로는 마지막 변수의 값을 계속 덮어씌워서 변수가 어떻게 변하는지 볼수가 없네요.
어떻게 방법이 없을까요? 꼭 좀 도와주세요~
(DB는 더 어려워서 그냥 txt파일에 출력하고 싶어요...)

public void onSensorChanged(int sensor, float[] values) {

if (sensor == SENSOR_ACCELEROMETER) {
long curTime = System.currentTimeMillis();
// only allow one update every 100ms, otherwise updates
// come way too fast and the phone gets bogged down
// with garbage collection
if (lastUpdate == -1 || (curTime - lastUpdate) > 100) {
lastUpdate = curTime;
x = values[DATA_X];
y = values[DATA_Y];
z = values[DATA_Z];
i=i+1;
xLabel.setText(String.format("X: %+2.5f (%+2.5f)", (x+cx), cx));
yLabel.setText(String.format("Y: %+2.5f (%+2.5f)", (y+cy), cy));
zLabel.setText(String.format("Z: %+2.5f (%+2.5f)", (z+cz), cz));

     final String tag = "SdcardWriteTest";
     String path ="/sdcard/";
     File file = new File(path+"myTest.txt");

     try{   
     FileOutputStream fos = new FileOutputStream(file);
     fos.write(String.format(String.format("X: %+2.5f ",x)).getBytes());
     }catch(IOException e){
     Log.i(tag , e.getMessage());
     }
    
}
}
}