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

  • Home
  • SEARCH
  • 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 8084503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:49:18+00:00 2026-06-05T17:49:18+00:00

Hi I have 3 classes first and second class are computations and 3rd is

  • 0

Hi I have 3 classes first and second class are computations and 3rd is where I save data from the first 2 classes to a text file.
I am attempting to reuse my method that writes calculated values from first and 2nd class into text file using FileWriter and BufferedWriter.

So i have something like this:
1) first class do calculations
2) then use 3rd class writeDetected to save it in text file
3) 2nd class do calculations
4) then use 3rd class again using writeDetected

Everything is working except when I wanted to save the calculations I’ve done in 2nd class. The contents in text file contains the previous (first class calculations) + the second class calculation. What I wanted to have is a file that has the calculation of first class and another file with 2nd class calculations. Any ideas on how I should do this?

edited:

Just to illustrate this:

it should look something like this

class 1 {1,2,3,4}

class 2 {5,6,7,8}

What I have at the moment is

class 1 {1,2,3,4}

class 2 {1,2,3,4,5,6,7,8}

this is my code:

public void writeDetected(){
    Scanner getFileName = new Scanner(System.in);

    //Enter file name here for first class then after calculation of  
    // 2nd class enter another file name
    String getInp = getFileName.nextLine();
    try{
        FileWriter theFile = new FileWriter(getInp);
        BufferedWriter readBuf = new BufferedWriter (theFile); 
        String convDoubleToString;

        for (Double getVal: detected){
            convDoubleToString = getVal.toString();

            readBuf.write(convDoubleToString);
            readBuf.newLine();
        }

        readBuf.close();

    }

    catch (IOException e){
        System.out.println(e);
    }
}
  • 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-05T17:49:20+00:00Added an answer on June 5, 2026 at 5:49 pm

    Try this,

    Sent the path from the calling method as Argument to the Parameters of the called method, in this way you can write your file content to whatever file you want (Here the called method will be writeMyFile(String path) )

    Eg:

    public void writeMyFile(String path){
    
    Scanner scan = new Scanner(System.in);
    
    File f = new File(path);
    
    FileWriter fr = new FileWriter(f);
    
    BufferedWriter br  = new BufferedWriter(fr);
    
    while(true){  // its a continuos loop, so better handle it the way u want it
    
     br.write(new Scanner(System.in).nextLine());
    
     } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .py file with lots of classes: class First(Second): #code class Third(Fourth):
i have a 2 data classes first: public class Question { public CharSequence question;
my code is like this: i have two classes first class: public class Box<E>
I have this application with 2 classes, in the first class I define a
Which static class initializes first if we have one more static classes in our
Let's say I have two classes. Each class has one parameter. Parameter of first
I have these classes: first: class C { public: C(const C& c):_s(c._s){} c():_s(){} string
I've just completed my second OOP class, and both my first and second classes
i have two classes first: .h file #ifndef Vandenynas_H #define Vandenynas_H #include <cstdlib> #include
If I have 2 classes and the first extends the second, how can the

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.