java.lang.IllegalArgumentException: contains a path separator
This method opens a file in the private data area of the application. You cannot open any files in subdirectories in this area or from entirely other areas using this method. So use the constructor of the FileInputStream
directly to pass the path with a directory in it.
IllegalArgumentException: File contains a path separator Android
You cannot use paths with slashes (/
) with openFileOutput()
. More importantly, you are trying to combine both getFilesDir()
and openFileOutput()
, which is unnecessary and is causing this problem.
Change your code to:
public void saveCustomButtonInfo (Context context, List<DocumentButtonInfo> info) throws Exception {
File dir = new File(context.getFilesDir(), "Load");
if(! dir.exists()){
dir.mkdir();
}
File f = new File(dir, "DocumentActivityCustomButtonsInfo.obj");
FileOutputStream out=new FileOutputStream(f);
ObjectOutputStream outObject=new ObjectOutputStream(out);
outObject.writeObject(info);
outObject.flush();
out.getFD().sync();
outObject.close();
}
Of note:
Vector
has been obsolete for ~15 years- Never use concatenation to build filesystem paths; use the proper
File
constructor - There is no point in catching an exception only to just re-throw it
- There is no point in returning a
boolean
that is alwaystrue
- Call
getFD().sync()
on aFileOutputStream
to confirm all bytes are written to disk
File contains a path separator.
write below code for that.
File file = getActivity().getFileStreamPath("/mnt/sdcard/photo/1342147146535.jpg");
if(file.exists()){
Toast.makeText(getActivity(), "File exists in /mnt", Toast.LENGTH_SHORT);
}
And Follow below link for more detail.
File Path
IllegalArgumentException: file contains path separator
file.exists is. But getFileStreamPath can't take a path, it needs to take a filename in that directory. Try this:
File file = new File(this.getFilesDir().getAbsolutePath() + "/thesubdirectory/the.zip");
new File() gives IllegalArgumentException: File contains a path separator
It seems that you are calling wrong function at InstallerService.java
line 30. Make sure you call your own deleteFile
by using class name before as: YourClass.deleteFile()
;
I think somehow ContextWrapper.deleteFile()
is called which doesn't accept path separator.
Related Topics
Hide/Show Bottomnavigationview on Scroll
Remove Listview Items in Android
How to Sign an Already Compiled APK
How to Do Http Authentication in Android
Android Studio Says "Cannot Resolve Symbol" But Project Compiles
Getview Returning Null When Fragment Has Been Created from an Activity
No Need to Cast the Result of Findviewbyid
Detecting When Screen Is Locked
Android Emulator: Could Not Get Wglgetextensionsstringarb Error
System Is Returning Error 127 When Called from C++ in Linux
How to Set Versionname in APK Filename Using Gradle
Dialogs/Alertdialogs: How to "Block Execution" While Dialog Is Up (.Net-Style)
How to Get the List of Running Applications
How to Delete a Whole Folder and Content
How to Create a Custom Home-Screen Replacement Application for Android