Programming
JAVA : write a method partitionFile?

Question 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.

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 (java.io.FileWriter) in the code itself.

khakaan (1456)
Carnegie Mellon University

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

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

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

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

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