Java读取文件内容,并在读到空格时换行,并写到另一个文件中,为什么我的这个程序无法实现?帮我看一下
importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.FileInputStre...
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;public class TestWriterClass1 {public static void main(String[] args) { try { FileInputStream fis = new FileInputStream("C:/Users/43571194/eclipse-workspace/JavaIOProject/学生信息.txt"); FileOutputStream fos = new FileOutputStream("C:/Users/43571194/eclipse-workspace/JavaIOProject/学生信息收集表.txt"); BufferedReader reader = new BufferedReader(new InputStreamReader(fis)); BufferedWriter write = new BufferedWriter(new OutputStreamWriter(fos)); String input=null; while((input=reader.readLine())!=null) { write.write(input); if (input==" ") write.write('\n'); } reader.close(); write.close(); } catch (IOException e) { e.printStackTrace(); } }
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询