本文整理匯總了Java中java.nio.file.Files.newBufferedReader方法的典型用法代碼示例。如果您正苦於以下問題:Java Files.newBufferedReader方法的具體用法?Java Files.newBufferedReader怎麽用?Java Files.newBufferedReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.file.Files
的用法示例。
在下文中一共展示了Files.newBufferedReader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readFile
import java.nio.file.Files; //導入方法依賴的package包/類
/**
* Reads the file specified by filename and returns the file content as a string.
* End of lines are replaced by a space.
*
* @param fileName the command line filename
* @return the file content as a string.
*/
private List<String> readFile(String fileName) {
List<String> result = Lists.newArrayList();
try (BufferedReader bufRead = Files.newBufferedReader(Paths.get(fileName), options.atFileCharset)) {
String line;
// Read through file one line at time. Print line # and line
while ((line = bufRead.readLine()) != null) {
// Allow empty lines and # comments in these at files
if (line.length() > 0 && !line.trim().startsWith("#")) {
result.add(line);
}
}
} catch (IOException e) {
throw new ParameterException("Could not read file " + fileName + ": " + e);
}
return result;
}
示例2: parseFile
import java.nio.file.Files; //導入方法依賴的package包/類
/**
* Parse given file.
*
* @param filePath
* Path to a file to parse.
* @throws IOException
* On error with reading given file.
*/
private void parseFile(Path filePath) throws IOException {
try (BufferedReader reader = Files.newBufferedReader(filePath,
StandardCharsets.UTF_8)) {
for (int i = 0; i < NUMBER_OF_LINES; i++) {
String line = reader.readLine();
if (line == null) {
throw new IllegalArgumentException(
"Missing line! Please check given file");
}
lines[i] = line;
}
parseDescription();
parseData();
parseLimits();
}
}
示例3: readUsersFromCSV
import java.nio.file.Files; //導入方法依賴的package包/類
private static List<User> readUsersFromCSV(String fileName){
List<User> users = new ArrayList<>();
Path pathToFile = Paths.get(fileName);
try(BufferedReader br = Files.newBufferedReader(pathToFile,StandardCharsets.US_ASCII)){
String line = br.readLine();
while(line != null) {
String[] attributes = line.split(",");
User user = createUser(attributes);
users.add(user);
line = br.readLine();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
return users;
}
示例4: checkStructuralEquivalenceWithListOfScalars
import java.nio.file.Files; //導入方法依賴的package包/類
@Test
public void checkStructuralEquivalenceWithListOfScalars() throws RepositoryException, BucketException, PersistentObjectException, IOException {
List<Integer> list = Arrays.asList(99, 88);
ClassWithListOfScalars example = new ClassWithListOfScalars(53, list);
scalar_list_bucket.makePersistent(example);
long id = example.getId();
// Now try and read back - avoid all cache etc.
Path file_path = store_path.resolve("REPOS").resolve(REPOSITORY_NAME).resolve(classWithListOfScalarsBucketName).resolve(Long.toString(id));
BufferedReader reader = Files.newBufferedReader(file_path, FileManipulation.FILE_CHARSET);
DynamicLXP lxp2 = new DynamicLXP(id, new JSONReader(reader), lxp_bucket);
assertEquals(id, lxp2.getId());
assertEquals(53, (int) lxp2.get("AN_INT"));
List l = (List) lxp2.get("A_LIST");
assertEquals(99, (int) l.get(0));
assertEquals(88, (int) l.get(1));
}
示例5: countDataPJson
import java.nio.file.Files; //導入方法依賴的package包/類
/**
* Count and return data pjson line.
* @return Total line number
*/
public long countDataPJson() {
Path pathInZip = pathMap.get(DATA_PJSON);
try (BufferedReader bufReader = Files.newBufferedReader(pathInZip, Charsets.UTF_8)) {
LineNumberReader reader = new LineNumberReader(bufReader);
while (true) {
long readByte = reader.skip(SKIP_DATA_NUM);
if (readByte == 0) {
break;
}
}
return reader.getLineNumber();
} catch (IOException e) {
throw PersoniumCoreException.Common.FILE_IO_ERROR.params("read data pjson from snapshot file").reason(e);
}
}
示例6: dispLog
import java.nio.file.Files; //導入方法依賴的package包/類
/**
* Obtains the persistent log stored in the clinet_log.dat file and displays it in the GUI.
*/
private static void dispLog ()
{
Path path = Paths.get( "client_log.dat" );
if ( Files.exists( path ) )
{
try ( BufferedReader in = Files.newBufferedReader( path ) )
{
String logLine;
while ( ( logLine = in.readLine() ) != null )
{
ServerGUI.getTextArea().append( logLine + System.lineSeparator() );
}
}
catch ( IOException e )
{
System.out.println( e.getMessage() );
}
}
}
示例7: get
import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public String get() {
Properties properties = new Properties();
try {
Path currentPath = Paths.get(".").toAbsolutePath().normalize();
Path configurationFilePath = currentPath.resolve("conf").resolve(CONFIGURATION_FILENAME);
BufferedReader bufferedReader = Files.newBufferedReader(configurationFilePath);
properties.load(bufferedReader);
} catch (IOException e) {
throw new UncheckedIOException("there is problem with " + CONFIGURATION_FILENAME, e);
}
return DEPLOY_OPTION + properties.getProperty("repository.id");
}
示例8: load
import java.nio.file.Files; //導入方法依賴的package包/類
public static SimulationDetailedParameters load(String fileName) {
SimulationDetailedParameters parameters = null;
Path file = PlatformConfig.defaultConfig().getConfigDir().resolve(fileName);
if (Files.exists(file)) {
parameters = new SimulationDetailedParameters(fileName);
try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
parse(reader, parameters);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
return parameters;
}
示例9: readSecurityIndexes
import java.nio.file.Files; //導入方法依賴的package包/類
protected static List<SecurityIndex> readSecurityIndexes(Path path) {
try (Reader reader = Files.newBufferedReader(path)) {
return SecurityIndexParser.fromXml("contingency", reader);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例10: getKioslavercMap
import java.nio.file.Files; //導入方法依賴的package包/類
/**
* Raturns map of keys and values from kioslaverc group Proxy settings.
*
* Reads "[userhome]/.kde/share/config/kioslaverc" file.
*
* @return Map of keys and values from kioslaverc group Proxy settings.
*/
private Map<String, String> getKioslavercMap() {
File kioslavercFile = new File(KIOSLAVERC_PATH);
Map<String, String> map = new HashMap<String, String>();
if (kioslavercFile.exists()) {
try (BufferedReader br = Files.newBufferedReader(kioslavercFile.toPath())) {
String line;
boolean inGroup = false;
while ((line = br.readLine()) != null) {
if (inGroup) {
if (line.contains(EQUALS)) {
int indexOfEquals = line.indexOf(EQUALS);
String key = line.substring(0, indexOfEquals);
String value = line.substring(indexOfEquals + 1);
map.put(key, value);
} else if (line.startsWith(SQ_BRACKET_LEFT)) {
break;
}
} else if (line.startsWith(KIOSLAVERC_PROXY_SETTINGS_GROUP)) {
inGroup = true;
}
}
} catch (IOException | InvalidPathException ex) {
LOGGER.log(Level.SEVERE, "Cannot read file: ", ex);
}
} else {
LOGGER.log(Level.WARNING, "KDE system proxy resolver: The kioslaverc file not found ({0})", KIOSLAVERC_PATH);
}
return map;
}
示例11: getReader
import java.nio.file.Files; //導入方法依賴的package包/類
public UindCoordinatesReader getReader(InclusionDependency uind) throws AlgorithmExecutionException {
if (!uindToPath.containsKey(uind)) {
throw new AlgorithmExecutionException(format("No coordinates file found for uind %s", uind));
}
try {
return new UindCoordinatesReader(uind, Files.newBufferedReader(uindToPath.get(uind)));
} catch (IOException e) {
throw new AlgorithmExecutionException(format("Error reading coordinates file for uind %s", uind), e);
}
}
開發者ID:HPI-Information-Systems,項目名稱:AdvancedDataProfilingSeminar,代碼行數:11,代碼來源:CoordinatesRepository.java
示例12: writeSpillFiles
import java.nio.file.Files; //導入方法依賴的package包/類
private void writeSpillFiles() throws IOException {
try (BufferedReader reader = Files.newBufferedReader(origin)) {
String line;
while ((line = reader.readLine()) != null) {
if (isInputLimitExceeded()) {
break;
}
values.add(line);
maybeWriteSpillFile();
}
}
}
示例13: writeXml
import java.nio.file.Files; //導入方法依賴的package包/類
public static void writeXml(Path configDir, Path xmlFile) throws IOException, XMLStreamException {
XMLOutputFactory output = XMLOutputFactory.newInstance();
try (Writer writer = Files.newBufferedWriter(xmlFile, StandardCharsets.UTF_8)) {
XMLStreamWriter xmlWriter = output.createXMLStreamWriter(writer);
try {
xmlWriter.writeStartDocument(StandardCharsets.UTF_8.toString(), "1.0");
xmlWriter.writeStartElement("config");
try (DirectoryStream<Path> ds = Files.newDirectoryStream(configDir, entry -> Files.isRegularFile(entry) && entry.getFileName().toString().endsWith(".properties"))) {
for (Path file : ds) {
String fileName = file.getFileName().toString();
String fileNameWithoutExtension = fileName.substring(0, fileName.length() - 11);
xmlWriter.writeStartElement(fileNameWithoutExtension);
Properties properties = new Properties();
try (Reader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
properties.load(reader);
}
for (String name : properties.stringPropertyNames()) {
String value = properties.getProperty(name);
xmlWriter.writeStartElement(name);
xmlWriter.writeCharacters(value);
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
}
}
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
} finally {
xmlWriter.close();
}
}
}
示例14: loadFile
import java.nio.file.Files; //導入方法依賴的package包/類
protected int loadFile ( final Path file, final Map<String, Map<String, Map<String, String>>> result ) throws IOException
{
try ( Reader reader = Files.newBufferedReader ( file, StandardCharsets.UTF_8 ) )
{
final Map<String, Map<String, Map<String, String>>> data = loadJsonData ( reader );
return OscarLoader.putAll ( result, data );
}
}
示例15: preprocessArgs
import java.nio.file.Files; //導入方法依賴的package包/類
/**
* Preprocess the command line arguments passed in by the shell. This method checks, for the first non-option
* argument, whether the file denoted by it begins with a shebang line. If so, it is assumed that execution in
* shebang mode is intended. The consequence of this is that the identified script file will be treated as the
* <em>only</em> script file, and all subsequent arguments will be regarded as arguments to the script.
* <p>
* This method canonicalizes the command line arguments to the form {@code <options> <script> -- <arguments>} if a
* shebang script is identified. On platforms that pass shebang arguments as single strings, the shebang arguments
* will be broken down into single arguments; whitespace is used as separator.
* <p>
* Shebang mode is entered regardless of whether the script is actually run directly from the shell, or indirectly
* via the {@code jjs} executable. It is the user's / script author's responsibility to ensure that the arguments
* given on the shebang line do not lead to a malformed argument sequence. In particular, the shebang arguments
* should not contain any whitespace for purposes other than separating arguments, as the different platforms deal
* with whitespace in different and incompatible ways.
* <p>
* @implNote Example:<ul>
* <li>Shebang line in {@code script.js}: {@code #!/path/to/jjs --language=es6}</li>
* <li>Command line: {@code ./script.js arg2}</li>
* <li>{@code args} array passed to Nashorn: {@code --language=es6,./script.js,arg}</li>
* <li>Required canonicalized arguments array: {@code --language=es6,./script.js,--,arg2}</li>
* </ul>
*
* @param args the command line arguments as passed into Nashorn.
* @return the passed and possibly canonicalized argument list
*/
private static String[] preprocessArgs(final String[] args) {
if (args.length == 0) {
return args;
}
final List<String> processedArgs = new ArrayList<>();
processedArgs.addAll(Arrays.asList(args));
// Nashorn supports passing multiple shebang arguments. On platforms that pass anything following the
// shebang interpreter notice as one argument, the first element of the argument array needs to be special-cased
// as it might actually contain several arguments. Mac OS X splits shebang arguments, other platforms don't.
// This special handling is also only necessary if the first argument actually starts with an option.
if (args[0].startsWith("-") && !System.getProperty("os.name", "generic").startsWith("Mac OS X")) {
processedArgs.addAll(0, tokenizeString(processedArgs.remove(0)));
}
int shebangFilePos = -1; // -1 signifies "none found"
// identify a shebang file and its position in the arguments array (if any)
for (int i = 0; i < processedArgs.size(); ++i) {
final String a = processedArgs.get(i);
if (!a.startsWith("-")) {
final Path p = Paths.get(a);
String l = "";
try (final BufferedReader r = Files.newBufferedReader(p)) {
l = r.readLine();
} catch (final IOException ioe) {
// ignore
}
if (l.startsWith("#!")) {
shebangFilePos = i;
}
// We're only checking the first non-option argument. If it's not a shebang file, we're in normal
// execution mode.
break;
}
}
if (shebangFilePos != -1) {
// Insert the argument separator after the shebang script file.
processedArgs.add(shebangFilePos + 1, "--");
}
return processedArgs.stream().toArray(String[]::new);
}