当前位置: 首页>>代码示例>>Java>>正文


Java Files.newBufferedReader方法代码示例

本文整理汇总了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;
}
 
开发者ID:georghinkel,项目名称:ttc2017smartGrids,代码行数:26,代码来源:JCommander.java

示例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();
    }
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:25,代码来源:ParserUtilty.java

示例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;
}
 
开发者ID:raisercostin,项目名称:dcsi,代码行数:19,代码来源:Tester1.java

示例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));
}
 
开发者ID:stacs-srg,项目名称:storr,代码行数:23,代码来源:ListTypeTest.java

示例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);
    }
}
 
开发者ID:personium,项目名称:personium-core,代码行数:20,代码来源:SnapshotFile.java

示例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() );
		}
	}
}
 
开发者ID:wjpmclawrence,项目名称:TechComparisonProject,代码行数:25,代码来源:Server.java

示例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");
}
 
开发者ID:ronbadur,项目名称:maven-artifacts-uploader,代码行数:16,代码来源:RepositoryIdProvider.java

示例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;
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:14,代码来源:SimulationDetailedParameters.java

示例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);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:8,代码来源:AbstractSecurityIndexTest.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:KdeNetworkProxy.java

示例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();
    }
  }
}
 
开发者ID:HPI-Information-Systems,项目名称:AdvancedDataProfilingSeminar,代码行数:13,代码来源:TPMMS.java

示例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();
        }
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:33,代码来源:PropertiesPlatformConfig.java

示例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 );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:9,代码来源:DirectoryScanner.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:69,代码来源:Shell.java


注:本文中的java.nio.file.Files.newBufferedReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。