缓冲区写入器不写入文件

发布于 2024-11-24 08:39:34 字数 1988 浏览 1 评论 0原文

缓冲区写入器未写入文件。请谁能告诉我可能是什么问题

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

怀中猫帐中妖 2024-12-01 08:39:35

将数据写入 BufferedWriter 后,尝试 flush() 然后 close() BufferedWriter。

Try to flush() and then close() your BufferedWriter after writing the data to it.

長街聽風 2024-12-01 08:39:35

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.

那小子欠揍 2024-12-01 08:39:35

完成写入后关闭 BufferedWriter

output.close();

Close your BufferedWriter after you're finished writing.

output.close();
画尸师 2024-12-01 08:39:35

你既不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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文