缓冲区写入器不写入文件
缓冲区写入器未写入文件。请谁能告诉我可能是什么问题
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Writer;
public class main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Writer output = null;
File file = new File("D:/junk/CI_CSSOIDs sql_query/orphans.log");
output = new BufferedWriter(new FileWriter(file));
java.io.FileReader fr = new FileReader( "D:/junk/CI_CSSOIDs ql_query/SQL_CSSO.log" ) ;
java.io.BufferedReader reader = new BufferedReader( fr ) ;
int orphancount=0;
String line = null ;
int count =1;
while( ( line = reader.readLine() ) != null )
{
String words[]=line.split(" ");
for (int i =0;i<words.length;i++){
if (words[i].length()==32){
String CIline=null;
java.io.FileReader CIfr = new FileReader( "D:/junk/CI_CSSOIDs sql_query/CI.log" ) ;
java.io.BufferedReader CIreader = new BufferedReader( CIfr ) ;
boolean orphan = true;
while((CIline=CIreader.readLine())!=null){
if (CIline.contains(words[i])){
orphan=false;
break;
}
}
if(orphan){
orphancount++;
output.write("####"+words[i]+"*****\n");
System.out.println(words[i]+" : is an orphan CSSOID");
}
}
}
count++;
}
System.out.println("Orphan count is :"+orphancount);
}
}
The bufferwriter is not writing to a file. Please can anyone tell me what could be the issue
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Writer;
public class main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Writer output = null;
File file = new File("D:/junk/CI_CSSOIDs sql_query/orphans.log");
output = new BufferedWriter(new FileWriter(file));
java.io.FileReader fr = new FileReader( "D:/junk/CI_CSSOIDs ql_query/SQL_CSSO.log" ) ;
java.io.BufferedReader reader = new BufferedReader( fr ) ;
int orphancount=0;
String line = null ;
int count =1;
while( ( line = reader.readLine() ) != null )
{
String words[]=line.split(" ");
for (int i =0;i<words.length;i++){
if (words[i].length()==32){
String CIline=null;
java.io.FileReader CIfr = new FileReader( "D:/junk/CI_CSSOIDs sql_query/CI.log" ) ;
java.io.BufferedReader CIreader = new BufferedReader( CIfr ) ;
boolean orphan = true;
while((CIline=CIreader.readLine())!=null){
if (CIline.contains(words[i])){
orphan=false;
break;
}
}
if(orphan){
orphancount++;
output.write("####"+words[i]+"*****\n");
System.out.println(words[i]+" : is an orphan CSSOID");
}
}
}
count++;
}
System.out.println("Orphan count is :"+orphancount);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将数据写入 BufferedWriter 后,尝试
flush()
然后close()
BufferedWriter。Try to
flush()
and thenclose()
your BufferedWriter after writing the data to it.BufferedWriter
缓冲写入。这意味着它将数据保留在内存中,直到缓冲区耗尽或刷新/关闭写入器。这样做是为了提高性能。我建议您关闭所有流/读取器/写入器,这也可以解决您的问题。
A
BufferedWriter
buffers writes. That means it keeps the data in memory until the buffer is exhausted or you flush/close the writer. It does this to improve performance.I suggest you close all your stream/reader/writers and that will fix your problem too.
完成写入后关闭
BufferedWriter
。Close your
BufferedWriter
after you're finished writing.你既不flush()也不close()作者。由于它是一个缓冲写入器,因此所有内容都存储在缓冲区中,直到您执行其中一项操作为止。
You neither flush() nor close() the writer. Since it's a buffered writer, all the stuff is stored up in the buffer until you do one of those.