I like to add a string to an existing file in the DCIM folder. The file with the first line is correctly made, but the next lines not.
mport java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.text.ParseException;
import android.content.Context;
public class SaveposImpl {
public void savestring(Integer w, String param) {
//String Filenm= "/storage/sdcard0/my_csv_file.csv";
String Filenm= "/storage/emulated/0/DCIM/Track.csv";
try{
com.codename1.io.File f=new com.codename1.io.File( Filenm );
if ( w==1) {
if(f.exists()){
f.delete();
f.createNewFile();
} else {
f.createNewFile();
}
boolean append = true;
FileOutputStream fOut = new FileOutputStream(Filenm, append );
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(param);
osw.flush();
osw.close(); } }
catch (Exception e) {
android.util.Log.d("failed to save file", e.toString());
}
}
import com.codename1.system.NativeInterface;
/**
*
* @author Administrator
*/
public interface Savepos extends NativeInterface {
public void savestring(Integer w, String param);
}
String param = w + ","+ Latp + ","+ Lonp + "," + TOGl + "," + speed + "," + acc;
Display.getInstance().invokeAndBlock(new Runnable() {
public void run() {
savepos1.savestring( w,param);
}
});