JAVA : write a method partitionFile?

Question Description

I have the following java program called MultiBufferedWriter

import;import java.util.ArrayList;import;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 = 0;


  public void close() throws IOException


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





  public void newLine() throws IOException


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







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.

Final 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 ( in the code itself.

khakaan (1456)
Carnegie Mellon University

I was on a very tight deadline but thanks to Studypool I was able to deliver my assignment on time.

The tutor was pretty knowledgeable, efficient and polite. Great service!

Heard about Studypool for a while and finally tried it. Glad I did caus this was really helpful.


Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors