Skip to content

Instantly share code, notes, and snippets.

@zafe
Last active August 29, 2015 14:22
Show Gist options
  • Save zafe/dfd6a8d0101fc7e3307e to your computer and use it in GitHub Desktop.
Save zafe/dfd6a8d0101fc7e3307e to your computer and use it in GitHub Desktop.
Write a file in android using FileWriter
package com.paad.comparison;
import java.io.FileOutputStream;
import java.io.FileWriter;
import android.app.Activity;
import android.os.Bundle;
public class ComparisonOfControlCreationActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
String string1 = "Hey you";
FileOutputStream fos ;
try {
fos = new FileOutputStream("/sdcard/filename.txt", true);
FileWriter fWriter;
try {
fWriter = new FileWriter(fos.getFD());
fWriter.write("hi");
fWriter.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
fos.getFD().sync();
fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment