java.nio.charset.spi
import java.nio.CharBuffer;
import java.nio.charset.spi.CharsetProvider;
public class CharBufferWrap {
public static void main(String[] args) {
// Get the default charset provider
CharsetProvider provider = CharsetProvider.provider();
// Create a char buffer
CharBuffer buffer = CharBuffer.wrap("Hello world");
// Get the charset for the buffer
String charsetName = provider.charsetForName(buffer.charset().name());
// Print the charset name
System.out.println(charsetName); // Output: UTF-8
}
}