src/main/java/org/ballerinax/hello/HelloPlugin.java
/**
     * Write content to a File. Create the required directories if they don't not exists.
     *
     * @param context        context of the file
     * @param targetFilePath target file path
     * @throws IOException If an error occurs when writing to a file
     */
Write content to a File. Create the required directories if they don't not exists.
@param context        context of the file
@param targetFilePath target file path
@throws IOException If an error occurs when writing to a file
Write content to a File . Create the required directories if they don ' t not exists . @param context context of the file @param targetFilePath target file path @throws IOException If an error occurs when writing to a file
public void writeToFile(String context, String targetFilePath) throws IOException {
        File newFile = new File(targetFilePath);
        if (newFile.exists()) {
            Files.write(Paths.get(targetFilePath), context.getBytes(StandardCharsets.UTF_8),
                    StandardOpenOption.APPEND);
            return;
        }
        if (newFile.getParentFile().mkdirs()) {
            Files.write(Paths.get(targetFilePath), context.getBytes(StandardCharsets.UTF_8));
            return;
        }
        Files.write(Paths.get(targetFilePath), context.getBytes(StandardCharsets.UTF_8));
    }
public void writeToFile ( String context , String targetFilePath ) throws IOException { File newFile = new File ( targetFilePath ) ; if ( newFile . exists ( ) ) { Files . write ( Paths . get ( targetFilePath ) , context . getBytes ( StandardCharsets . UTF_8 ) , StandardOpenOption . APPEND ) ; return ; } if ( newFile . getParentFile ( ) . mkdirs ( ) ) { Files . write ( Paths . get ( targetFilePath ) , context . getBytes ( StandardCharsets . UTF_8 ) ) ; return ; } Files . write ( Paths . get ( targetFilePath ) , context . getBytes ( StandardCharsets . UTF_8 ) ) ; }
Write content to a File.
Write content to a File .
// append if file exists //create required directories