Java.Lang.Illegalargumentexception: Contains a Path Separator

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 always true
  • Call getFD().sync() on a FileOutputStream 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



Leave a reply



Submit