• Home
  • Blog
  • JAVA : write a method partitionFile?

JAVA : write a method partitionFile?

0 comments

I have the following java program called MultiBufferedWriter

import java.io.BufferedWriter;
import java.io.FileWriter;import java.util.ArrayList;import java.io.IOException;import java.util.Scanner;

public class MultiBufferedWriter{

  private ArrayList<BufferedWriter> writers;
  private int currentFile;  public MultiBufferedWriter(String filePattern, int n) throws IOException  {

    this.currentFile = 0;
   ArrayList<BufferedWriter> dog = new ArrayList<BufferedWriter>();    writers = dog; for(int i = 0; i < n; i++) {  BufferedWriter out = new BufferedWriter(new FileWriter(filePattern+(i+1)));writers.add(out);  }}

  public void write(String mouse) throws IOException
{
for(int i = 0; i < writers.size(); i++){writers.get(currentFile).write(mouse); 

      currentFile++;

    }

    currentFile = 0;

  }

  public void close() throws IOException

  {

    for(int i = 0; i < writers.size(); i++)

    {

    writers.get(i).close();

    } 

  }

  public void newLine() throws IOException

  {

    for(int i = 0; i < writers.size();i++)

    {

    writers.get(currentFile).newLine();

    }

  }

}

___________________________________________________________________________

How do i write a method partitionFile which takes as input a String souce a String destination and an int n. Using the class MultiBufferedWriter( which i have written out already and it compiles) it should partition the source file into several files with the pattern destination + i for ranges of i to 1 until n.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}