public static void main(String[] args) throws IOException {
File f = new File("a.txt");
if (!f.exists()) {//首先判断文件是否存在
throw new IOException("文件不存在");
}
FileInputStream fis = new FileInputStream(f);
byte[] bytes = new byte[fis.available()];
fis.read(bytes);
System.out.println(new String(bytes));//这里将文件的内容读写出来
String st = new String(bytes);//将文件内容转化为字符串,方便遍历
StringBuilder sb = new StringBuilder(st);
System.out.println();
Set set = new HashSet();//用HashSet可以实现去重的效果
for (int i = 0; i < sb.length(); i++) {
set.add(sb.charAt(i));
}
System.out.println(set);
ArrayList list = new ArrayList();//再将去重后的数据存入list集合里方便排序
for (Object o : set) {
list.add(o);
}
Collections.sort(list);
System.out.println(list);
FileOutputStream fos=new FileOutputStream("b.txt");
for (int i = 0; i < list.size(); i++) {
fos.write((char)list.get(i));
}
fos.flush();;
fos.close();
}
public static void main(String[] args) throws IOException { File f = new File("a.txt"); if (!f.exists()) {//首先判断文件是否存在 throw new IOException("文件不存在"); } FileInputStream fis = new FileInputStream(f); byt.