Here you can find the source of readFile(Path directory, String... parts)
directory/parts[0]/parts[1]/.../parts[n]
using ISO_8859_1.
Parameter | Description |
---|---|
directory | root directory for resolve |
parts | parts of the path relative to directory |
Parameter | Description |
---|---|
IOException | in case file can not be read |
public static List<String> readFile(Path directory, String... parts) throws IOException
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; public class Main { /**// w w w . ja v a2 s. c o m * Reads the file under the <code>directory/parts[0]/parts[1]/.../parts[n]</code> * using ISO_8859_1. * * @param directory root directory for resolve * @param parts parts of the path relative to directory * @return the List<String> of lines of the file * @throws IOException in case file can not be read */ public static List<String> readFile(Path directory, String... parts) throws IOException { return readFile(resolve(directory, parts)); } /** * Reads the <code>file</code> using ISO_8859_1. * * @param file file to read * @return the List<String></String> of lines of the file * @throws IOException in case file can not be read */ public static List<String> readFile(Path file) throws IOException { return Files.readAllLines(file, StandardCharsets.ISO_8859_1); } /** * Resolves the Path to the file or directory under the <code> * directory/parts[0]/parts[1]/.../parts[n]</code>. * * @param directory root directory for resolve * @param parts parts of the path relative to directory * @return resolved Path */ public static Path resolve(Path directory, String... parts) { Path current = directory; for (String part : parts) { current = current.resolve(part); } return current; } }