请教一个关于输入输出到txt文件的问题 本帖最后由 yangkuanku 于 2009-09-16 19:57:55 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 D:\\Homeworks\\eclipse work place\\SuanFa\\src\\class1\\output.txt路径中最好不要有空格,改改看。 没看明白你的题是什么意思,我做了个简单的,你参照一下吧,希望对你有帮助。 FileReader rf = null; FileWriter fw = null; BufferedReader br = null; try { rf = new FileReader("d://a.txt"); fw = new FileWriter("d://b.txt"); br = new BufferedReader(rf); char [] str = br.readLine().toCharArray(); Map map = new HashMap(); for(int i=0;i<str.length;i++){ if(map.containsKey(str[i])) map.put(str[i],(Integer) map.get(str[i])+1); else map.put(str[i],1); } fw.write(map.toString()); System.out.println(map); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch(IOException ce){ ce.printStackTrace(); } finally{ try{ fw.flush(); fw.close(); br.close(); rf.close(); }catch(Exception ce){ ce.printStackTrace(); } } 对了忘说了 a.txt里写的是123412938749这样的数。 一个JAVA问题,我迷惑了。。。。 小疑问 jsf文件下载不提示对话框 关于c3p0的问题 请大家踊跃发言 若是高手就多说几句 在DAO中,对某一列进行更新,如何提高速度 Acegi 中的角色必须以ROLE_开始吗 compass+jdbc+mysql跑自带例子petclinic报错 hsqldb的session过期问题 dhcp记录sql操作日志的问题 struts2 dtd文件导入无法提示并且报错 org.springframework.beans.factory.BeanCreationException mybatis模糊查询出现“索引 1 超出范围”
路径中最好不要有空格,改改看。
FileReader rf = null;
FileWriter fw = null;
BufferedReader br = null;
try {
rf = new FileReader("d://a.txt");
fw = new FileWriter("d://b.txt");
br = new BufferedReader(rf);
char [] str = br.readLine().toCharArray();
Map map = new HashMap();
for(int i=0;i<str.length;i++){
if(map.containsKey(str[i]))
map.put(str[i],(Integer) map.get(str[i])+1);
else
map.put(str[i],1);
}
fw.write(map.toString());
System.out.println(map);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(IOException ce){
ce.printStackTrace();
}
finally{
try{
fw.flush();
fw.close();
br.close();
rf.close();
}catch(Exception ce){
ce.printStackTrace();
}
}