有人能告诉我Eclipse为什么会给我错误:
Exception in thread "main" java.io.IOException: Stream closed
at java.io.BufferedWriter.ensureOpen(Unknown Source)
at java.io.BufferedWriter.write(Unknown Source)
at java.io.Writer.write(Unknown Source)
at javadruckdruck.main(javadruckdruck.java:52)
我无法得到它。我证明它十次,但它不起作用。
import java.io.*;
public class javadruckdruck {
public static void main(String[] args) throws IOException
{
//scanning
FileReader fr = new FileReader ("fax_user.csv") ;
BufferedReader br = new BufferedReader (fr) ;
FileWriter fw = new FileWriter("Druckausgabe.txt") ;
BufferedWriter bw = new BufferedWriter (fw) ;
String textnow = br.readLine () ;
// bw.write (Email);
// bw.close();
while (textnow !=null) {
//Umlaute gegen ae,oe,ue tauschen
String text = textnow ;
String textXreplaced = text ;
textXreplaced = text.replace ("ä","ae") ;
String textXXreplaced = textXreplaced ;
textXXreplaced = textXreplaced.replace ("ü","ue") ;
String textXXXreplaced = textXXreplaced ;
textXXXreplaced = textXXreplaced.replace ("ö","oe");
String textXXXXreplaced= textXXXreplaced.replace("ß","ss");
textXXXXreplaced = textXXXreplaced ;
//Text umformatieren, splitten, E-Mail, Nummer anhängen
String textreplaced = textXXXXreplaced.replace(" ", "") ;
String textreplacedtwo = textreplaced.replace("\"","") ;
String textreplacedthree = textreplacedtwo.replace(";","");
String [] parts = textreplacedthree.split("[,]") ;
String part1 = parts[0] ;
String part2 = parts[1] ;
String part3 = parts[2] ;
String Email = "@bogestra.de" ;
String Zahlen = ";3" ;
String finished = part3 + "." + part2 + Email + Zahlen + part1;
textnow = br.readLine () ;
bw.write (finished);
bw.close();
//System Ausgabe
//System.out.println(part3 + "." + part2 + Email + Zahlen + part1 );
}
br.close();
}
}
答案 0 :(得分:0)
你在循环中关闭了bw。你应该把这条线移到循环之外:
public static void main(String[] args) throws IOException
{
//scanning
FileReader fr = new FileReader ("fax_user.csv") ;
BufferedReader br = new BufferedReader (fr) ;
FileWriter fw = new FileWriter("Druckausgabe.txt") ;
BufferedWriter bw = new BufferedWriter (fw) ;
String textnow = br.readLine () ;
// bw.write (Email);
// bw.close();
while (textnow !=null) {
//Umlaute gegen ae,oe,ue tauschen
String text = textnow ;
String textXreplaced = text ;
textXreplaced = text.replace ("ä","ae") ;
String textXXreplaced = textXreplaced ;
textXXreplaced = textXreplaced.replace ("ü","ue") ;
String textXXXreplaced = textXXreplaced ;
textXXXreplaced = textXXreplaced.replace ("ö","oe");
String textXXXXreplaced= textXXXreplaced.replace("ß","ss");
textXXXXreplaced = textXXXreplaced ;
//Text umformatieren, splitten, E-Mail, Nummer anhängen
String textreplaced = textXXXXreplaced.replace(" ", "") ;
String textreplacedtwo = textreplaced.replace("\"","") ;
String textreplacedthree = textreplacedtwo.replace(";","");
String [] parts = textreplacedthree.split("[,]") ;
String part1 = parts[0] ;
String part2 = parts[1] ;
String part3 = parts[2] ;
String Email = "@bogestra.de" ;
String Zahlen = ";3" ;
String finished = part3 + "." + part2 + Email + Zahlen + part1;
textnow = br.readLine () ;
bw.write (finished);
//System Ausgabe
//System.out.println(part3 + "." + part2 + Email + Zahlen + part1 );
}
bw.close();
br.close();
}