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 6537149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:34:57+00:00 2026-05-25T10:34:57+00:00

I have a problem with my code. Basically I’m trying to save 5 strings

  • 0

I have a problem with my code. Basically I’m trying to save 5 strings to a file, and then when the class opens read the txt file and recover the 5 strings. However I only recover one, and not the 5. Am I saving the code incorrectly?

public class Activity2 extends Activity {
/** Called when the activity is first created. */
boolean checkTick = false;
Activity1 one;
Boolean [] Checkboxs = {false,false,false,false,false};
String [] Storetype = {"","","","",""};
ArrayList<Boolean> bList = new ArrayList<Boolean>(); 
ArrayList<String> sList = new ArrayList<String>(); 

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings);

    readFile();

    final Button buttonHOME = (Button) findViewById(R.id.widget900);         
    buttonHOME.setOnClickListener(new ViewStub.OnClickListener() {             
     @Override
     public void onClick(View view) {
      Intent myIntent = new Intent(view.getContext(), Activity1.class);
            startActivityForResult(myIntent, 0);
            finish();
        }

     });
    final Button buttonEXIT = (Button) findViewById(R.id.widget41);         
    buttonEXIT.setOnClickListener(new ViewStub.OnClickListener() {             
     @Override
    public void onClick(View arg0) {
          System.exit(0);


       }         });

    final CheckBox checkBox =
       ( CheckBox ) findViewById( R.id.widget36 );
          checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
           {


        @Override
           public void onCheckedChanged(CompoundButton arg0,boolean arg1) {
           if(checkBox.isChecked()){
       // TODO Auto-generated method stub
          checkTick = true;
               Checkboxs[0] = true;

               storeValue();
                 System.out.println("newthing" + checkTick);
 }
               if(!checkBox.isChecked()){
             checkTick = false;
  Checkboxs[0] = false;
  storeValue();
 }
}
             });

            if(checkTick){
            //if(Checkboxs[0])
              checkBox.setChecked(checkTick);
                 }

     }

public void storeValue(){

  String storeType = "";

  for(int i = 0; i < 5; i++){
      if(Checkboxs[i]){
         Storetype[i] = "true";
   }
   else{
       Storetype[i] = "false";
   }
  }
  //if(checkTick){
  // storeType = "true";

 // }
 // else{
 //  storeType = "false";
 //  }

  try{


  FileOutputStream fOut = openFileOutput("samplefile.txt", 
                MODE_WORLD_READABLE);
  OutputStreamWriter osw = new OutputStreamWriter(fOut); 

  // Write the string to the file
  for(int i = 0; i < 5; i++){
   osw.write(Storetype[i] + "\n");
  }

  //osw.write(storeType);
  /* ensure that everything is 
   * really written out and close */

  osw.flush();
  osw.close();
  System.out.println("The value is now stored in a file" + storeType);
  }catch (IOException ioe){
   ioe.printStackTrace();
  }
  System.out.println("The value is now stored" + storeType);
 }
public void readFile(){
 try{
        String datahold = "";

        FileInputStream fIn = openFileInput("samplefile.txt");
        DataInputStream isr = new DataInputStream(fIn);
        BufferedReader br = new BufferedReader(new InputStreamReader(isr));


        // Transform the chars to a String
       // if(datahold.equals("true")){
        // checkTick = true;

      //  }
      //  else{
        // checkTick = false;
       // }
        while((datahold = br.readLine()) != null){
         sList.add(datahold);
        }
        for(int i = 0; i < sList.size(); i++){
         System.out.println("ARRAY" + sList.get(i));
        }

 } catch (IOException ioe) {
        ioe.printStackTrace();
 }


}
     public void autoSign(boolean checkTickTwo){
     checkTick = checkTickTwo;
    }




}
  • 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-05-25T10:34:57+00:00Added an answer on May 25, 2026 at 10:34 am

    Because that’s OSWs default behaviour. Use BufferedWriter instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple code that basically opens mappoint and imports addresses into it then
I have a code that basically solves one of the problem in Project Euler
I have a problem with the following javascript code. Basically I want to run
I have the following code within the class. basically what i need is it
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
Possible Duplicate: What's wrong with Delphi's “with” I am have a problem debugging code
I have a problem with the following code: for(i = 0;(i - 1)< n;i++)
I have an intermittent problem with some code that writes to a Windows Event
The following code demonstrates a weird problem I have in a Turbo C++ Explorer
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button

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.