本文整理了Java中java.nio.file.Files.newBufferedReader()
方法的一些代码示例,展示了Files.newBufferedReader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.newBufferedReader()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:newBufferedReader
暂无
代码示例来源:origin: jenkinsci/jenkins
/**
* Opens the text file at <code>path</code> for reading using charset
* {@link java.nio.charset.StandardCharsets#UTF_8}.
* @param path Path to the file to open for reading.
* @throws IOException if the file at <code>path</code> cannot be opened for
* reading.
*/
public LinesStream(@Nonnull Path path) throws IOException {
in = Files.newBufferedReader(path); // uses UTF-8 by default
}
代码示例来源:origin: apache/kafka
protected Reader reader(String path) throws IOException {
return Files.newBufferedReader(Paths.get(path));
}
代码示例来源:origin: springside/springside4
public static BufferedReader asBufferedReader(Path path) throws IOException {
Validate.notNull(path, "path is null");
return Files.newBufferedReader(path, Charsets.UTF_8);
}
代码示例来源:origin: pmd/pmd
public Map<String, Object> loadSidebar() throws IOException {
try (Reader reader = Files.newBufferedReader(sidebarPath, StandardCharsets.UTF_8)) {
Yaml yaml = new Yaml();
@SuppressWarnings("unchecked")
Map<String, Object> sidebar = (Map<String, Object>) yaml.load(reader);
return sidebar;
}
}
代码示例来源:origin: lets-blade/blade
public static String readToString(Path path) throws IOException {
BufferedReader bufferedReader = Files.newBufferedReader(path);
return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
}
代码示例来源:origin: lets-blade/blade
public static String readToString(Path path) throws IOException {
BufferedReader bufferedReader = Files.newBufferedReader(path);
return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
}
代码示例来源:origin: redisson/redisson
/**
* Reads path content.
*/
public static String readString(Path path) throws IOException {
BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);
StringWriter writer = new StringWriter();
StreamUtil.copy(reader, writer);
return writer.toString();
}
代码示例来源:origin: apache/ignite
/**
* @param path Path.
* @return Read line.
* @throws IOException If failed.
*/
@Nullable private static String readLine(@NotNull Path path) throws IOException {
try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
return reader.readLine();
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Reads the entire contents and returns it.
*/
public String read() throws IOException {
StringWriter out = new StringWriter();
PrintWriter w = new PrintWriter(out);
try (BufferedReader in = Files.newBufferedReader(Util.fileToPath(file), StandardCharsets.UTF_8)) {
String line;
while ((line = in.readLine()) != null)
w.println(line);
} catch (Exception e) {
throw new IOException("Failed to fully read " + file, e);
}
return out.toString();
}
代码示例来源:origin: pmd/pmd
public FileIterable(File file) {
try {
lineReader = new LineNumberReader(Files.newBufferedReader(file.toPath(), Charset.defaultCharset()));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: pxb1988/dex2jar
public static void smaliFile(Path path, DexFileVisitor dcv) throws IOException {
try (Reader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
ANTLRInputStream is = new ANTLRInputStream(reader);
is.name = path.toString();
smali0(dcv, is);
}
}
代码示例来源:origin: pxb1988/dex2jar
public static ClassNode parse(Path file) throws IOException {
try (BufferedReader bufferedReader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
return parse(file.toString(), bufferedReader);
} catch (RecognitionException e) {
throw new RuntimeException("Fail to assemble " + file, e);
}
}
代码示例来源:origin: org.assertj/assertj-core
@VisibleForTesting
public List<Delta<String>> diff(Path actual, Charset actualCharset, Path expected, Charset expectedCharset) throws IOException {
return diff(newBufferedReader(actual, actualCharset), newBufferedReader(expected, expectedCharset));
}
代码示例来源:origin: SonarSource/sonarqube
public Report parse() {
try (Reader reader = Files.newBufferedReader(filePath, StandardCharsets.UTF_8)) {
return validate(gson.fromJson(reader, Report.class));
} catch (JsonIOException | IOException e) {
throw new IllegalStateException("Failed to read external issues report '" + filePath + "'", e);
} catch (JsonSyntaxException e) {
throw new IllegalStateException("Failed to read external issues report '" + filePath + "': invalid JSON syntax", e);
}
}
代码示例来源:origin: oblac/jodd
/**
* Reads path content.
*/
public static String readString(final Path path) throws IOException {
try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
StringWriter writer = new StringWriter(); // flush & close not needed for StringWriter-instance
StreamUtil.copy(reader, writer);
return writer.toString();
}
}
代码示例来源:origin: MovingBlocks/Terasology
public static GameManifest load(Path filePath) throws IOException {
try (BufferedReader reader = Files.newBufferedReader(filePath, TerasologyConstants.CHARSET)) {
return createGson().fromJson(reader, GameManifest.class);
}
}
代码示例来源:origin: google/guava
@Override
public String getSinkContents() throws IOException {
Path file = getPath();
try (Reader reader = java.nio.file.Files.newBufferedReader(file, Charsets.UTF_8)) {
StringBuilder builder = new StringBuilder();
for (int c = reader.read(); c != -1; c = reader.read()) {
builder.append((char) c);
}
return builder.toString();
}
}
}
代码示例来源:origin: org.assertj/assertj-core
@VisibleForTesting
public List<Delta<String>> diff(Path actual, String expected, Charset charset) throws IOException {
return diff(newBufferedReader(actual, charset), readerFor(expected));
}
代码示例来源:origin: SonarSource/sonarqube
private void addToIndex(File file) throws IOException {
List<Block> blocks = bridge.chunk(file.getAbsolutePath(), file.getAbsolutePath(), Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8));
for (Block block : blocks) {
index.insert(block);
}
}
代码示例来源:origin: azkaban/azkaban
public static void main(final String[] args) throws Exception {
final String propsFile = System.getenv("JOB_PROP_FILE");
final Properties prop = new Properties();
prop.load(Files.newBufferedReader(Paths.get(propsFile), StandardCharsets.UTF_8));
final String jobName = System.getenv("JOB_NAME");
final SleepJavaJob job = new SleepJavaJob(jobName, prop);
job.run();
}
内容来源于网络,如有侵权,请联系作者删除!