- public static void main(String[] args) throws Exception {
- FileReader fr=new FileReader("E:\\a.txt");
- BufferedReader br=new BufferedReader(fr);
- char[] ch=new char[15];
- while((fr.read())!=-1){
- br.read(ch);
- }
-
- Arrays.sort(ch);
-
- BufferedWriter bw = new BufferedWriter(new FileWriter("E:\\b.txt"));
-
- bw.write(ch, 0, ch.length);
-
- br.close();
- bw.close();
-
- }
复制代码
a.txt的内容假设为为字符串“abcd”
为什么运行我这个代码,写到b.txt以后,第一个字符总是丢失(实际上是空格)
求大神指点 |