前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >guava-IO使用

guava-IO使用

作者头像
用户5166556
发布2019-04-16 12:41:16
6000
发布2019-04-16 12:41:16
举报
代码语言:javascript
复制
@Test
	public void test1() throws IOException {
		// Read the lines of a UTF-8 text file
		File file = new File("F:/prd/kw/olay1.txt");
		ImmutableList<String> lines = Files.asCharSource(file, Charsets.UTF_8).readLines();
		for (String line : lines) {
			System.out.println(line);
		}
	}

	@Test
	public void test2() throws IOException {
		// Count distinct word occurrences in a file
		Multiset<String> wordOccurrences = HashMultiset.create(Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings().split(Files.asCharSource(new File("F:/prd/kw/test.txt"), Charsets.UTF_8).read()));
		System.out.println(wordOccurrences);
	}

	@Test
	public void test3() throws IOException {
		File file = new File("F:/prd/kw/olay1.txt");
		HashCode hash = Files.asByteSource(file).hash(Hashing.sha1());
		System.out.println(hash);
	}

	@Test
	public void test4() throws MalformedURLException, IOException {
		File file = new File("F:/prd/kw/ok.txt");
		// Copy the data from a URL to a file
		Resources.asByteSource(new URL("http://ifeve.com/google-guava-io/")).copyTo(Files.asByteSink(file));
	}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015年02月05日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档