/**
* 对{@link Map}中元素以key排序后,每行以{key}={value}形式输出到{@link Writer}<br>
* map为空或null时则不向writer写入任何内容
* @param map
* @param writer 为null抛出{@link IllegalArgumentException}
* @throws IOException
*/
public static void storeSortedMap(Map<String,String> map,Writer writer) throws IOException {
if(null==writer)
throw new IllegalArgumentException("the arugment 'writer' must not be null ");
TreeMap<String, String> sortedMap = new TreeMap<String,String>();
if(null!=map)
sortedMap.putAll(map);
BufferedWriter bw=(writer instanceof BufferedWriter)?(BufferedWriter)writer
: new BufferedWriter(writer);
for (Entry<String,String> e:sortedMap.entrySet()) {
bw.write(e.getKey() + "=" + e.getValue());
bw.newLine();
}
bw.flush();
}
/**
* 对 {@link Collection}中元素排序后(去除重复),元素分行输出到{@link Writer}<br>
* collection为空或null时则不向writer写入任何内容
* @param collection
* @param writer 为null抛出{@link IllegalArgumentException}
* @throws IOException
*/
public static void storeSortedSet(Collection<String> collection,Writer writer) throws IOException {
if(null==writer)
throw new IllegalArgumentException("the arugment 'writer' must not be null ");
TreeSet<String> sortedSet = new TreeSet<String>();
if(null!=collection)
sortedSet.addAll(collection);
BufferedWriter bw=(writer instanceof BufferedWriter)?(BufferedWriter)writer
: new BufferedWriter(writer);
for (String e:sortedSet) {
bw.write(e);
bw.newLine();
}
bw.flush();
}
Map<String,String> map;
//....
storeSortedMap(map,new FileWriter(new File("c:\\id.txt")));
Set<String,String> set;
//....
storeSortedSet(set,new FileWriter(new File("c:\\trainval.txt")));
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有