I have already created a file and I want to open it. After creating the file with some common opening text, I call the method, writeValuestoFile(String fname) where fname is the File Name. In the method, I would like to open the file I already created through another method and just update it. But, I am InvalidArgumentException. I am doubting if my path I am specifying is correct or not. Input will be highly appreciated. This is my method call.
public void writeValuestoFile(String fname) {
String rec_x_string = Float.valueOf((x_updated)).toString();
String rec_y_string = Float.valueOf((y_updated)).toString();
String rec_z_string = Float.valueOf((z_updated)).toString();
try {
FileOutputStream fout = openFileOutput("sdcard/Accelorometer Readings/"+file_name, Context.MODE_APPEND);
OutputStreamWriter write = new OutputStreamWriter(fout);
String newline = System.getProperty("line.seperator");
try {
write.append(newline);
write.append(newline);
write.write(rec_x_string + " " + rec_y_string + " " + rec_z_string);
write.flush();
write.close();
fout.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
This is my Logcat for the exception:
02-08 05:57:49.869: E/AndroidRuntime(24818): FATAL EXCEPTION: main
02-08 05:57:49.869: E/AndroidRuntime(24818): java.lang.IllegalArgumentException: File sdcard/Accelorometer Readings/null contains a path separator
02-08 05:57:49.869: E/AndroidRuntime(24818): at android.app.ContextImpl.makeFilename(ContextImpl.java:1674)
02-08 05:57:49.869: E/AndroidRuntime(24818): at android.app.ContextImpl.openFileOutput(ContextImpl.java:420)
02-08 05:57:49.869: E/AndroidRuntime(24818): at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:158)
02-08 05:57:49.869: E/AndroidRuntime(24818): at com.example.hw02_devarajan_q1.MainActivity.writeValuestoFile(MainActivity.java:241)
02-08 05:57:49.869: E/AndroidRuntime(24818): at com.example.hw02_devarajan_q1.MainActivity$2.run(MainActivity.java:91)
02-08 05:57:49.869: E/AndroidRuntime(24818): at android.os.Handler.handleCallback(Handler.java:587)
02-08 05:57:49.869: E/AndroidRuntime(24818): at android.os.Handler.dispatchMessage(Handler.java:92)
02-08 05:57:49.869: E/AndroidRuntime(24818): at android.os.Looper.loop(Looper.java:130)
02-08 05:57:49.869: E/AndroidRuntime(24818): at android.app.ActivityThread.main(ActivityThread.java:3687)
02-08 05:57:49.869: E/AndroidRuntime(24818): at java.lang.reflect.Method.invokeNative(Native Method)
02-08 05:57:49.869: E/AndroidRuntime(24818): at java.lang.reflect.Method.invoke(Method.java:507)
02-08 05:57:49.869: E/AndroidRuntime(24818): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
02-08 05:57:49.869: E/AndroidRuntime(24818): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
02-08 05:57:49.869: E/AndroidRuntime(24818): at dalvik.system.NativeStart.main(Native Method)