Here you can find the source of writeStringContents(String contents, WritableByteChannel channel)
public static void writeStringContents(String contents, WritableByteChannel channel) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; import java.nio.charset.StandardCharsets; public class Main { /** Writes String contents to channel and closes it. */ public static void writeStringContents(String contents, WritableByteChannel channel) throws IOException { // TODO Checks if a supplier would be nice try {//from w w w . j a v a2s.co m ByteBuffer buffer = ByteBuffer.wrap(contents.getBytes(StandardCharsets.UTF_8)); channel.write(buffer); } finally { channel.close(); } } }