Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8287765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:08:10+00:00 2026-06-08T12:08:10+00:00

I am writing a test program and in it I write the results to

  • 0

I am writing a test program and in it I write the results to 2 different files. 1 file for the specific test and 1 file that keeps a running total of the all the results. Rather than writing the logic out for each of the 20 tests that I have, I would like to create a method that will return an array of BufferedWriters. Is this possible?

Here is the code that I have been working with:

    public BufferedWriter[] createTestFile(String fileName, String fileName2) throws IOException{
    File directory = null;
    File photoDirectory = null;
    BufferedWriter bufWrite=null; 
    BufferedWriter bw2 = null;

    BufferedWriter[] bw[]=null; 

    SimpleDateFormat photoFormat = new SimpleDateFormat("ddMMyy-hhmmss");

    new SimpleDateFormat("MMMddyy-hhmmss");
    /*
     * This sections checks the phone to see if there is a SD card. if
     * there is an SD card, a directory is created on the SD card to
     * store the test log results. If there is not a SD card, then the
     * directory is created on the phones internal hard drive
     */
    // if there is no SD card
    if (Environment.getExternalStorageState() == null) {
        directory = new File(Environment.getDataDirectory()
                + "/RobotiumTestLog/");
        photoDirectory = new File(Environment.getDataDirectory()
                + "/Robotium-Screenshots/");

        // if no directory exists, create new directory
        if (!directory.exists()) {
            directory.mkdir();
        }

        // if phone DOES have sd card
    } else if (Environment.getExternalStorageState() != null) {
        // search for directory on SD card
        directory = new File(Environment.getExternalStorageDirectory()
                + "/RobotiumTestLog/");
        photoDirectory = new File(
                Environment.getExternalStorageDirectory()
                        + "/Robotium-Screenshots/");

        // if no directory exists, create new directory to store test
        // results
        if (!directory.exists()) {
            directory.mkdir();
        }
    }// end of SD card checking

    /*
     * Checks for existing test logs, and if they exist, they are
     * deleted, creating a new test log for each testing method
     */
    File logResults = new File(directory, fileName);
    File totLogRes = new File(directory, fileName2); 
    if (logResults.exists()) {
        logResults.delete();
    }
    if (!logResults.exists()) {
        logResults.createNewFile();
    }
    //check total Log
    if (!totLogRes.exists()) {
        totLogRes.createNewFile();
    }
    /*
     * This creates the writing stream to log the test results This
     * stream MUST be closed, using bw.close(), for the test results to
     * show on the log. If the stream is not closed, when you open the
     * text file that the results are stored in, the page will be blank.
     */

        //This is where I have a problem. I'm not sure how to return an array of bufferedwriters
    bufWrite = new BufferedWriter(new FileWriter(logResults, true));
    bw2= new BufferedWriter(new FileWriter(totLogRes, true)); 

    bw[0]=bufWrite; <---- get an error here saying I can't go from array to bw.

    return bw[]; 

I have tried a couple different ways, but I get errors. I was wondering if someone could point me in the right direction.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:08:13+00:00Added an answer on June 8, 2026 at 12:08 pm

    You should change the declaration of bw to:

    BufferedWriter[] bw=new BufferedWriter[2]; 
    

    Right now, you are declaring and array of arrays of BufferedWriter. And you are not allocating it…

    Also, the return statement should be

    return bw;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a small test program that gives the following xml file as
I'm writing a program similar to a diagnostic program , that runs a test
I'm trying to write a basic Erlang program that reads in a file in
I am writing a test program to copy some file in Application data folder
I have a program that takes two files as an argument. The first file
Here is my minimal example: program test implicit none real :: testfunc write(*,*) Writing
I'm writing a program that will take in an equation and check if all
I'm writing a simple test program to pass multidimensional arrays. I've been struggling to
So I'm writing a program to test the endianess of a machine and print
I'm writing test code that needs to clean up the entities it creates when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.