I have an activity which creates a new java object and it executes methods inside that object. One of the methods uses a fileoutputstream with a file and directory defined in the activity and the method includes writing some data to this file and then closing it. I've tested this on version 4 and 5 devices and it works with no problems but when I go to an android 6/7 device, the fileoutputstream throws a FileNotFoundException claiming that the there is no such file or directory and the app crashes but I'm confused because it does exist (file name/directory doesn't change between the different versions) as if it didn't exist, the earlier versions of android would have thrown this error as well.
I understand there was a change in how permissions were handled for users from android 5 to android 6 but I don't know how or whether to use that to fix the issue. The permission to write to external storage is already in my Manifest file , the file directory includes the Environment.getExternalStorageDirectory() method and the current target sdk is 23 (android version 6).
Please advise on what might be causing the problem and what I would need to do to resolve this.