JAVA : write a method partitionFile?

User Generated

Xunanx

Programming

Description

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.

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

The only reason I can think of is that you have a class called FileWriter in the same package as the class, from which you've copied the code fragments. In that case, you are not allowed to import a FileWriter class from a different package, but have to use the qualified name (java.io.FileWriter) in the code itself.

Similar Content

Related Tags