src/main/java/de/blau/android/util/FileUtil.java
/**
     * Open a local file for writing generating any necessary directories
     * 
     * @param context Android Context
     * @param fileName name of the filw we want to write to
     * @return a File object
     * @throws IOException if we can't create the directories
     */
Open a local file for writing generating any necessary directories

@param context Android Context
@param fileName name of the filw we want to write to
@return a File object
@throws IOException if we can't create the directories
Open a local file for writing generating any necessary directories @param context Android Context @param fileName name of the filw we want to write to @return a File object @throws IOException if we can ' t create the directories
@NonNull
    public static File openFileForWriting(@NonNull Context context, @NonNull final String fileName) throws IOException {
        File outfile = new File(fileName);
        String parent = outfile.getParent();
        if (parent == null) { 
            outfile = new File(FileUtil.getPublicDirectory(), fileName);
        } else { 
            File outdir = new File(parent);
            outdir.mkdirs();
            if (!outdir.isDirectory()) {
                throw new IOException("Unable to create directory " + outdir.getPath());
            }
        }
        return outfile;
    }
@ NonNull public static File openFileForWriting ( @ NonNull Context context , @ NonNull final String fileName ) throws IOException { File outfile = new File ( fileName ) ; String parent = outfile . getParent ( ) ; if ( parent == null ) { outfile = new File ( FileUtil . getPublicDirectory ( ) , fileName ) ; } else { File outdir = new File ( parent ) ; outdir . mkdirs ( ) ; if ( ! outdir . isDirectory ( ) ) { throw new IOException ( "Unable to create directory " + outdir . getPath ( ) ) ; } } return outfile ; }
Open a local file for writing generating any necessary directories
Open a local file for writing generating any necessary directories
// no directory specified, save to standard location // ensure directory exists // noinspection ResultOfMethodCallIgnored