博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IO练习之统计单词数并写入文件
阅读量:3959 次
发布时间:2019-05-24

本文共 842 字,大约阅读时间需要 2 分钟。

题目实现

用代码实现以下需求

(1)有如下字符串"If you want to change your fate I think you must learn java"
(2)打印格式:
    to=3
    think=1
    you=2
    //........
(3)按照上面的打印格式将内容写入到D:\\count.txt文件中(要求用高效流)

 

代码实现

public class demo {	public static void main(String[] args) throws IOException {				String string = "If you want to change your fate I think you must learn java";				String[] strings = string.split(" ");		Map
map = new HashMap<>(); for(String s:strings) { int count = 0; if(map.containsKey(s)) { count = map.get(s); } count++; map.put(s,count); } BufferedWriter b = new BufferedWriter(new FileWriter("D:/count.txt")); Set
> set = map.entrySet(); for(Entry
entry:set) { System.out.println(entry); b.write(entry.getKey()+"="+entry.getValue()); b.newLine(); } b.close(); System.out.println("完成"); }}

 

转载地址:http://jpazi.baihongyu.com/

你可能感兴趣的文章
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Android 下 JNI 开发
查看>>
Mysql索引
查看>>
OGNL投影查询
查看>>
OGNL投影查询
查看>>
OGNL投影查询
查看>>
Redis之RDB和AOF持久化
查看>>
Redis之RDB和AOF持久化
查看>>