How To Read and Write File in to the SDCARD


/*Write  the file  in to the sdcard*/

public static void WriteFile(String filenames, String content) {

File file = new File("/sdcard/", filenames);
if (file.exists() || (!file.exists())) {
            FileOutputStream fos = null;
try {
fos = new FileOutputStream(file, false);
} catch (FileNotFoundException e) {

e.printStackTrace();
}
            try {
fos.write(content.getBytes());
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
         
}
}

/*Read From the file present in to the sdcard*/
public static String ReadFile() {
String filenameRead1 = "GreatRepChartURL.txt";
File myFileRead1 = new File("/sdcard/", filenameRead1);
if (myFileRead1.exists()) {
FileInputStream fInRead1 = null;
try {
fInRead1 = new FileInputStream(myFileRead1);

}

catch (FileNotFoundException e2) {
e2.printStackTrace();
}

String string1 = "";
try {
BufferedReader readerRead1 = new BufferedReader(
new InputStreamReader(fInRead1));

string1 = readerRead1.readLine();
SERVER_ADDRESS = string1;
setCheckingFile(0);
} catch (IOException e1) {
e1.printStackTrace();
}

}
else
{
setCheckingFile(1);
}
return SERVER_ADDRESS;
}

Comments

Popular posts from this blog

Bluetooth Data Transfer Example

DeCompile .apk file on ubuntu 14.04