Here you can find the source of readFile(Bundle bundle, String path, Charset cs)
Parameter | Description |
---|---|
bundle | the bundle that contains the text resource |
path | the path of the resource |
cs | the character set to use |
Parameter | Description |
---|---|
IOException | if the resource cannot be read |
public static String readFile(Bundle bundle, String path, Charset cs) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Scanner; import org.osgi.framework.Bundle; public class Main { /**//from w w w. ja v a2s. c o m * Uses UTF-8 character encoding * @param bundle the bundle that contains the text resource * @param path the path of the resource * @return the content as string (including line delimiters) * @throws IOException if the resource cannot be read */ public static String readFile(Bundle bundle, String path) throws IOException { return readFile(bundle, path, StandardCharsets.UTF_8); } /** * @param bundle the bundle that contains the text resource * @param path the path of the resource * @param cs the character set to use * @return the content as string (including line delimiters) * @throws IOException if the resource cannot be read */ public static String readFile(Bundle bundle, String path, Charset cs) throws IOException { URL jsonUrl = bundle.getEntry(path); try (Scanner scanner = new Scanner(jsonUrl.openStream(), cs.name())) { scanner.useDelimiter("\\A"); if (scanner.hasNext()) { return scanner.next(); } else { throw new IOException("no content"); } } } }