안녕하세요 안드로이드 개발 초보입니다.
가속도 센서에 관련된 앱을 개발하려고 하는데요
가속도 센서를 출력하는 코드는 오프소스로 구했는데,
그 값이 변할때마다 txt파일에 저장하려고 합니다.
제가 코드를 짜보았는데 처음 값만 저장이 되고 다음 값부터는 기록이 되지 않네요.
(우선 x값만 저장하도록 짜보았습니다.)
고수님들 무엇이 잘못됬는지 알려주시면 정말 감사하겠습니다.

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];

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+“output.txt");

      try{

        FileOutputStream fos = new FileOutputStream(file);

        fos.write(String.format(String.format("X: %+2.5f (%+2.5f)", (x+cx), cx)).getBytes());

                  fos.close();

         }catch(IOException e){

                    Log.i(tag , e.getMessage());

                   }

    

}
}
}