[solved]-Trying Overwrite File Every Time Close Application Q39034404
I am trying to overwrite the file every time i close theapplication.


import android.annotation. SuppressLint; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; import android.view.Velocity Tracker; import android.view.View; import android.widget.LinearLayout; import android.widget. TextView; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class TestSingle Touch extends Activity { TextView textPressure, textSize; float pressure = 0f; float size=Of; private Velocity Tracker mVelocity Tracker = null; FileWriter touch Writer; @Override @SuppressLint(“Clickable ViewAccessibility”) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LinearLayout mainLayout = findViewById(R.id.mainLayout); textPressure = findViewById(R.id.pressure); textSize = findViewById(R.id.size); File file = new File(this.getFiles Dir, “touch Writer.txt”); // create a file in internal storage, so that it is only accessible by the app try touch Writer = new FileWriter(file,true); // open the file in append mode } catch (IOException e) { nobile curgh (IOExceptio12635 PM @ 1730 mainLayout.setOn TouchListener(on TouchListener); private View.On TouchListener on TouchListener = new View.On TouchListener() { @Override public boolean on Touch(View view, MotionEvent event) { pressure = event.getPressure(); size = event.getSize(); return false; @Override @SuppressLint(“SetTextI18n”) public boolean on TouchEvent(MotionEvent event) { pressure = event.getPressure(); size = event.getSize(); textPressure.setText(“pressure :” +pressure); textSize.setText(“size: “+size); // output the pressure and size to file try { touch Writer.write(“nPressure : “+pressure+” nSize *+size): } catch (IOException e) { int index = event.getActionIndex(); int action = event.getAction Masked(); int pointerld = event.getPointerldindex); switch(action) 130 lobildnturpinterld event29 perldindex); switch(action) case MotionEvent.ACTION DOWN: if(mVelocity Tracker == null) // Retreive a new Velocity Tracker object to watch the velocity of a motion mVelocity Tracker = Velocity Tracker.obtain(); else //Reset the velocity tracker back to its initial state mVelocity Tracker.clear(); // add a user’s movement to the tracker mVelocity Tracker.addMovement(event); break; case MotionEvent.ACTION MOVE: mVelocity Tracker.addMovement(event); // when you want to determine the velocity, call // computeCurrentVelocityo. Then call getXVelocity lland get YVelocity to retrieve the velocity for each pointer ID mVelocity Tracker.computeCurrent Velocity(1000); Log.d(“”,”X velocity : “+m Velocity Tracker.getX Velocity(pointerld)); Log.d(“”,”Y velocity : “+m Velocity Tracker.getY Velocity(pointerld)); // output x and y velocity to file try { touchWriter.write(“nX Velocity : “+m Velocity Tracker.getX Velocity(pointerld)); touch Writer.write(“n Y Velocity : “+m Velocity Tracker.getY Velocity (pointerld)); } catch (IOException e) { break; case MotionEvent.ACTION_UP: break; case MotionEvent.ACTION CANCEL: // Return awelovita telerabie haelta bene obile HD 2:35 PM @ 30 m Velocity Tracker.computeCurrentVelocity(1000); Log.d(“”,”X velocity : “+m Velocity Tracker.getX Velocity (pointerld)); Log.d(“”,”Y velocity : “+m Velocity Tracker.getY Velocity (pointerid)); // output x and y velocity to file try touchWriter.write(“nX Velocity : “+m Velocity Tracker.getX Velocity(pointerld)); touch Writer.write(“n Y Velocity : “+m Velocity Tracker.getY Velocity(pointerld)); } catch (IOException e) { break; case MotionEvent.ACTION_UP: break; case MotionEvent.ACTION CANCEL: // Return a velocity tracker object back to be re- used by others mVelocity Tracker.recycle(); break; return true; @Override protected void onDestroy { super.onDestroy(); try touch Writer.close(); // close the file when the activity is destroyed } catch (IOException e) { Show transcribed image text import android.annotation. SuppressLint; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; import android.view.Velocity Tracker; import android.view.View; import android.widget.LinearLayout; import android.widget. TextView; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class TestSingle Touch extends Activity { TextView textPressure, textSize; float pressure = 0f; float size=Of; private Velocity Tracker mVelocity Tracker = null; FileWriter touch Writer; @Override @SuppressLint(“Clickable ViewAccessibility”) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LinearLayout mainLayout = findViewById(R.id.mainLayout); textPressure = findViewById(R.id.pressure); textSize = findViewById(R.id.size); File file = new File(this.getFiles Dir, “touch Writer.txt”); // create a file in internal storage, so that it is only accessible by the app try touch Writer = new FileWriter(file,true); // open the file in append mode } catch (IOException e) {
nobile curgh (IOExceptio12635 PM @ 1730 mainLayout.setOn TouchListener(on TouchListener); private View.On TouchListener on TouchListener = new View.On TouchListener() { @Override public boolean on Touch(View view, MotionEvent event) { pressure = event.getPressure(); size = event.getSize(); return false; @Override @SuppressLint(“SetTextI18n”) public boolean on TouchEvent(MotionEvent event) { pressure = event.getPressure(); size = event.getSize(); textPressure.setText(“pressure :” +pressure); textSize.setText(“size: “+size); // output the pressure and size to file try { touch Writer.write(“nPressure : “+pressure+” nSize *+size): } catch (IOException e) { int index = event.getActionIndex(); int action = event.getAction Masked(); int pointerld = event.getPointerldindex); switch(action)
130 lobildnturpinterld event29 perldindex); switch(action) case MotionEvent.ACTION DOWN: if(mVelocity Tracker == null) // Retreive a new Velocity Tracker object to watch the velocity of a motion mVelocity Tracker = Velocity Tracker.obtain(); else //Reset the velocity tracker back to its initial state mVelocity Tracker.clear(); // add a user’s movement to the tracker mVelocity Tracker.addMovement(event); break; case MotionEvent.ACTION MOVE: mVelocity Tracker.addMovement(event); // when you want to determine the velocity, call // computeCurrentVelocityo. Then call getXVelocity lland get YVelocity to retrieve the velocity for each pointer ID mVelocity Tracker.computeCurrent Velocity(1000); Log.d(“”,”X velocity : “+m Velocity Tracker.getX Velocity(pointerld)); Log.d(“”,”Y velocity : “+m Velocity Tracker.getY Velocity(pointerld)); // output x and y velocity to file try { touchWriter.write(“nX Velocity : “+m Velocity Tracker.getX Velocity(pointerld)); touch Writer.write(“n Y Velocity : “+m Velocity Tracker.getY Velocity (pointerld)); } catch (IOException e) { break; case MotionEvent.ACTION_UP: break; case MotionEvent.ACTION CANCEL: // Return awelovita telerabie haelta bene
obile HD 2:35 PM @ 30 m Velocity Tracker.computeCurrentVelocity(1000); Log.d(“”,”X velocity : “+m Velocity Tracker.getX Velocity (pointerld)); Log.d(“”,”Y velocity : “+m Velocity Tracker.getY Velocity (pointerid)); // output x and y velocity to file try touchWriter.write(“nX Velocity : “+m Velocity Tracker.getX Velocity(pointerld)); touch Writer.write(“n Y Velocity : “+m Velocity Tracker.getY Velocity(pointerld)); } catch (IOException e) { break; case MotionEvent.ACTION_UP: break; case MotionEvent.ACTION CANCEL: // Return a velocity tracker object back to be re- used by others mVelocity Tracker.recycle(); break; return true; @Override protected void onDestroy { super.onDestroy(); try touch Writer.close(); // close the file when the activity is destroyed } catch (IOException e) {
Expert Answer
Answer to I am trying to overwrite the file every time i close the application. … . . .
OR

