Click here to Skip to main content
16,021,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
import java.io.*;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
class Test {
public static void main(String[] args)throws IOException
 {
    BufferedReader input;
    String line;
    File intermediate = new File("myfile1.txt");
    PrintWriter output = new PrintWriter(intermediate, "UTF-8");
    String p = "hh";
    File dir = new File(p);
    File[] files = dir.listFiles();
    for (File f : files) 
{
      if (f.isFile())
 {
        input = new BufferedReader(new FileReader(f));
        line = String.format("[%s_DINAMALAR_DATE]", f.getName());
        output.println(line);
        System.out.println(line);
        while ((line = input.readLine()) != null) 
{
          output.println(line);
          System.out.println(line);
        }
        input.close();
      }
    }
    output.close();
    input = new BufferedReader(new FileReader(intermediate));
    int count = 0;
    output = null;
    while ((line = input.readLine()) != null) 
{
      if (line.startsWith("["))
 {
        if (output != null) output.close();
        output = new PrintWriter(new File(line + ".txt"), "UTF-8");
        output.println(line);
        count++;
        continue;
      }
      output.println(line);
    }
    input.close();
  }
}
Posted
Comments
[no name] 18-Dec-15 3:47am    
Use your debugger to find out which variable is null, and correct it. Does dir contain anything, does it return a set of files?
Member 12200805 18-Dec-15 5:32am    
yes sir i have some files in the dir...

1 solution

Be sure that the path
Java
String p = "hh";

exists. I mean that the path must be a real and complete path. Hope this help.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900