當前位置: 首頁>>代碼示例>>Java>>正文


Java Files.lines方法代碼示例

本文整理匯總了Java中java.nio.file.Files.lines方法的典型用法代碼示例。如果您正苦於以下問題:Java Files.lines方法的具體用法?Java Files.lines怎麽用?Java Files.lines使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.lines方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: PrintUsageInspector

import java.nio.file.Files; //導入方法依賴的package包/類
PrintUsageInspector(Path printUsageFile) throws IOException {
  printedUsage = new HashMap<>();
  try (Stream<String> lines = Files.lines(printUsageFile)) {
    lines.forEach(line -> {
      if (line.startsWith("    ")) {
        if (line.contains("(") && line.contains(")")) {
          readMethod(line);
        } else {
          readField(line);
        }
      } else {
        readClazz(line);
      }
    });
  }
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:17,代碼來源:PrintUsageTest.java

示例2: generatePointCloud

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Helper method for creating a large amount of points.
 *
 * @return Large amount of points.
 */
private List<Vector> generatePointCloud() throws URISyntaxException {
    List<Vector> pointCloud = new ArrayList<Vector>(2000);

    try (Stream<String> stream = Files.lines(Paths.get(
            PointCloudCrustImplTest.class.getResource(RES_POINTS).toURI()
    ))) {

        stream.forEach(it -> {
            String[] s = it.split("\\s+");
            pointCloud.add(new Vector(
                    Float.valueOf(s[8]),
                    Float.valueOf(s[9]),
                    Float.valueOf(s[10]),
                    s[0]
            ));

        });

    } catch (IOException e) {
        e.printStackTrace();
    }

    return pointCloud;
}
 
開發者ID:ricebean-net,項目名稱:PointCloudCrust,代碼行數:30,代碼來源:PointCloudCrustImplTest.java

示例3: parseArtistLinks

import java.nio.file.Files; //導入方法依賴的package包/類
private List<Artist> parseArtistLinks(List<Artist> artists) {
    Map<String, List<Artist>> artistMap = artists.stream()
            .filter(album -> !StringUtils.isEmpty(album.getPk()))
            .collect(Collectors.groupingBy(Artist::getPk));

    //read file into stream, try-with-resources
    try (Stream<String> stream = Files.lines(Paths.get(artistUrlsPath))) {
        stream.map(strRow -> strRow.split(TAB_SYMBOL))
                .forEach(row -> {
                    List<Artist> artistList = artistMap.get(row[2]);
                    if (artistList != null) {
                        artistList.forEach(artist -> artist.getLinks().add(new ArtistUrlLink(row[1], row[3])));
                    }
                });
    } catch (IOException e) {
        e.printStackTrace();
    }

    return artists;
}
 
開發者ID:mapr-demos,項目名稱:mapr-music,代碼行數:21,代碼來源:ArtistParser.java

示例4: main

import java.nio.file.Files; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
  Path input = Paths.get(args[0]);
  Path output = Paths.get(args[1]);
  Map<String, Set<String>> indexMap = indexMap();
  try(Stream<String> lines = Files.lines(input)) {
    Stream<String> stream = lines
        .flatMap(tokens -> findClassAndMethodName(tokens).stream())
        .flatMap(name -> {
          Set<String> sigs = indexMap.get(name);
          //System.out.println("sigs " + sigs + " name " + name); 
          return (sigs == null)? Stream.of(name): sigs.stream();
        })
        .map(methodName -> "compileOnly " + methodName);
    Files.write(output, (Iterable<String>)stream.sorted().distinct()::iterator);
  }
}
 
開發者ID:forax,項目名稱:moduletools,代碼行數:17,代碼來源:JITTraceReader.java

示例5: read

import java.nio.file.Files; //導入方法依賴的package包/類
static RunManifest read(Path manifestPath) throws IOException {
  final Stream<String> lines = Files.lines(manifestPath);

  final RunManifestBuilder builder = new RunManifestBuilder();
  lines.forEachOrdered(line -> {
    if (line.trim().isEmpty()) {
      return;
    }

    final String[] split = line.trim().split(" ", 2);
    if (split.length != 2) {
      throw new IllegalArgumentException("Malformed manifest line '" + line + "'");
    }

    switch (split[0].charAt(0)) {
      case LAMBDA:
        builder.continuation(split[1]);
        break;

      case CLASSPATH_FILE:
        builder.addClassPathFile(split[1]);
        break;

      case REGULAR_FILE:
        builder.addFile(split[1]);
        break;

      default:
        LOG.warn("Unrecognized manifest entry '" + line + "'");
    }
  });

  return builder.build();
}
 
開發者ID:spotify,項目名稱:hype,代碼行數:35,代碼來源:ManifestUtil.java

示例6: loadTextFile

import java.nio.file.Files; //導入方法依賴的package包/類
private void loadTextFile(String filename, Consumer<String> processor) {
	try (Stream<String> stream = Files.lines(Paths.get(filename))) {
		stream.filter(line -> {return !line.startsWith("#") && 
				                      !line.trim().equals("");})
			  .forEach(processor);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
開發者ID:interpss,項目名稱:DeepMachineLearning,代碼行數:10,代碼來源:NetCaseConfiguration.java

示例7: fileLines

import java.nio.file.Files; //導入方法依賴的package包/類
private Stream<String> fileLines(File file) {
    try {
        return Files.lines(file.toPath());
    } catch (IOException io) {
        throw new PluginException("Couldn't read file");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:GenerateJLIClassesPlugin.java

示例8: readCitiesFromFile

import java.nio.file.Files; //導入方法依賴的package包/類
private List<Point2D> readCitiesFromFile() throws IOException {
    List<Point2D>  cities     = new ArrayList<>(8092);
    String         citiesFile = (Main.class.getResource("cities.txt").toExternalForm()).replace("file:", "");
    Stream<String> lines      = Files.lines(Paths.get(citiesFile));
    lines.forEach(line -> {
        String city[] = line.split(",");
        double[] xy = World.latLonToXY(Double.parseDouble(city[1]), Double.parseDouble(city[2]));
        cities.add(new Point2D(xy[0], xy[1]));
    });
    lines.close();
    return cities;
}
 
開發者ID:HanSolo,項目名稱:worldheatmap,代碼行數:13,代碼來源:Main.java

示例9: testConstructException

import java.nio.file.Files; //導入方法依賴的package包/類
public void testConstructException() {
    try (Stream<String> s = Files.lines(testFolder.resolve("notExist"), Charset.forName("UTF-8"))) {
        s.forEach(l -> fail("File is not even exist!"));
    } catch (IOException ioe) {
        assertTrue(ioe instanceof NoSuchFileException);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:StreamTest.java

示例10: load

import java.nio.file.Files; //導入方法依賴的package包/類
public void load() throws IOException {
  // Get metric name and put it in a map and assign it a number.
  // Add ts and value to metric store with that number.
  try (Stream<String> lines = Files.lines(filePath, Charset.defaultCharset())) {
    lines.forEachOrdered(line -> {
      if (line == null || line.isEmpty()) { // Ignore empty lines
        return;
      }
      try {
        String[] metricParts = line.split(" ");
        if (metricParts.length > 1 && metricParts[0].equals("put")) {
          String metricName = metricParts[1].trim();
          List<String> rawTags = Arrays.asList(metricParts).subList(4, metricParts.length);
          Metric metric = new Metric(metricName, rawTags);
          long ts = Long.parseLong(metricParts[2].trim());
          double value = Double.parseDouble(metricParts[3].trim());

          // System.out.println(metric.fullMetricName);

          int id = -1;
          if (metricidHashMap.containsKey(metric.fullMetricName)) {
            id = metricidHashMap.get(metric.fullMetricName);
          } else {
            metricCounter[0] = metricCounter[0] + 1;
            metricidHashMap.put(metric.fullMetricName, metricCounter[0]);
            id = metricCounter[0];
          }

          store.addPoint(id, ts, value);
        }
      } catch (Exception e) {
        // System.out.println("Error ingesting line " + line + " with exception " + e.getMessage());
      }
    });
  }
  metricidHashMap.clear();
  // System.out.println("Metric counter size: " + metricCounter[0]);
}
 
開發者ID:pinterest,項目名稱:yuvi,代碼行數:39,代碼來源:VarBitMetricStoreBenchmark.java

示例11: elideStartUpFromSave

import java.nio.file.Files; //導入方法依賴的package包/類
public void elideStartUpFromSave() throws IOException {
    Compiler compiler = new Compiler();
    Path path = compiler.getPath("myfile");
    test(
            (a) -> assertCommandOutputContains(a, "123", "==> 123"),
            (a) -> assertCommand(a, "/save " + path.toString(), "")
    );
    try (Stream<String> lines = Files.lines(path)) {
        assertEquals(lines.count(), 1, "Expected only one saved line");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:ToolBasicTest.java

示例12: setName

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Chooses a random name for the entity from a file.
 * 
 * @param names The file containing the potential name choices
 * @param numOfNames The number of names in the file
 */
public void setName(File names, int numOfNames)
{
	Stream<String> lines = null;
	try
	{
		lines = Files.lines(names.toPath());
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}
	name = lines.skip((int) (Math.random() * numOfNames)).findFirst().get();
}
 
開發者ID:Chroniaro,項目名稱:What-Happened-to-Station-7,代碼行數:20,代碼來源:Entity.java

示例13: load

import java.nio.file.Files; //導入方法依賴的package包/類
private Stream<String> load(String filename) {
    try {
        return Files.lines(Paths.get(
            new PathMatchingResourcePatternResolver()
                .getResource(filename)
                .getURI()
        ));
    } catch (final IOException ex) {
        throw new RuntimeException("Could not find required file '" +
                                       filename + "' on classpath.");
    }
}
 
開發者ID:membaza,項目名稱:email-service,代碼行數:13,代碼來源:SenderService.java

示例14: parseUrls

import java.nio.file.Files; //導入方法依賴的package包/類
private List<Artist> parseUrls(List<Artist> artists) {


        Map<String, List<Artist>> urlArtistMap = new HashMap<>();
        artists.stream()
                .filter(artist -> !artist.getLinks().isEmpty())
                .forEach(artist -> {
                    artist.getLinks().forEach(artistUrlLink -> {
                        if (!urlArtistMap.containsKey(artistUrlLink.getUrlId())) {
                            urlArtistMap.put(artistUrlLink.getUrlId(), new ArrayList<>());
                        }
                        urlArtistMap.get(artistUrlLink.getUrlId()).add(artist);
                    });
                });

        //read file into stream, try-with-resources
        try (Stream<String> stream = Files.lines(Paths.get(urlsPath))) {
            stream.map(strRow -> strRow.split(TAB_SYMBOL))
                    .forEach(row -> {
                        List<Artist> artistsWithSuchUrlList = urlArtistMap.get(row[0]);
                        if (artistsWithSuchUrlList != null) {

                            String pictureUrl = (row[2].contains("commons.wikimedia")) ? getActualWikiImageURL(row[2]) : row[2];

                            artistsWithSuchUrlList.forEach(artist -> {

                                if (artist.getProfileImageUrl() == null || artist.getProfileImageUrl().isEmpty()) {
                                    artist.setProfileImageUrl(pictureUrl);
                                } else {
                                    artist.addImageUrl(pictureUrl);
                                }
                            });
                        }
                    });
        } catch (IOException e) {
            e.printStackTrace();
        }

        return artists;
    }
 
開發者ID:mapr-demos,項目名稱:mapr-music,代碼行數:41,代碼來源:ArtistParser.java

示例15: main

import java.nio.file.Files; //導入方法依賴的package包/類
public static void main(String[] args) throws URISyntaxException, IOException {
    Path p = Paths.get(ClassLoader.getSystemResource(SRC).toURI());
    Stream<String> lines = Files.lines(p);
    int[] temperatures = parseTemperature(lines).toArray();
    // out.println(streamMax(lines));
    out.println(intStreamMax(stream(temperatures)));
    for (int i = 0; i < 10; i++) {
        // out.println(streamAverage1(stream(temperatures)));
        out.println(streamAverage2(stream(temperatures)));
        // out.println(streamAverage3(stream(temperatures)));
    }
}
 
開發者ID:isel-leic-mpd,項目名稱:mpd-2017-i41d,代碼行數:13,代碼來源:App.java


注:本文中的java.nio.file.Files.lines方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。