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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:22:51+00:00 2026-05-25T14:22:51+00:00

I am trying to create an application that is able to write text into

  • 0

I am trying to create an application that is able to write text into text file in Blackberry. I am able to write text inside the text file, but when I try to write a new line of text, it just overwrites the text I write into previously. Can anyone help me? I try to look for the forums around but no one has the specific solution that I needed.

Below is my code:

package filepackage;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Vector;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;

import net.rim.device.api.io.File;
import net.rim.device.api.system.Application;

public class WritingText extends Application{
    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */ 
    public static void main(String[] args){

        WritingText app = new WritingText();
        app.setAcceptEvents(false);

        Vector v = new Vector();
        v.addElement("Test2seconds.mp3");
        v.addElement("Test2seconds2.mp3");
        v.addElement("Test2seconds3.mp3");
        v.addElement("Test2seconds4.mp3");
        v.addElement("blind_willie.mp3");

        for(int i=0;i<v.size();i++){
        try 
        {
          FileConnection fc = (FileConnection)Connector.open("file:///SDCard/newfile.txt");
          // If no exception is thrown, then the URI is valid, but the file may or may not exist.
          if (!fc.exists())
          {
              fc.create();  // create the file if it doesn't exist
          }
          OutputStream outStream = fc.openOutputStream(); 
          outStream.write(((String) v.elementAt(i)).getBytes());

          String br = "\r\n";
          outStream.write (br.getBytes ());

          outStream.close();
          fc.close();
         }
         catch (IOException ioe) 
         {
            System.out.println(ioe.getMessage() );
         }
       }
    }
}

Please help me. 🙁

  • 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-25T14:22:52+00:00Added an answer on May 25, 2026 at 2:22 pm

    Looks like you’re creating a new file for each item in the vector. Try moving in the loop to surround only the write-operations:

    .----
    |     try 
    |     {
    |       FileConnection fc = (FileConnection)Connector.open(...);
    |      // If no exception is thrown, then the URI is valid
    |      if (!fc.exists())
    |      {
    |          fc.create();  // create the file if it doesn't exist
    |      }
    |      OutputStream outStream = fc.openOutputStream(); 
    |
    '-->  for(int i=0;i<v.size();i++){
    
          outStream.write(((String) v.elementAt(i)).getBytes());
    
          String br = "\r\n";
          outStream.write (br.getBytes ());
    .--> }
    |
    |      outStream.close();
    |      fc.close();
    |     }
    |     catch (IOException ioe) 
    |     {
    |        System.out.println(ioe.getMessage() );
    |     }
    |   }
    '--
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a WPF application that takes command line arguments. If
I'm trying to create a simple Silverlight application that involves parsing a CSV file
I'm trying to create a windowless Ogre application, but it seems that the method
I'm trying to create an application that will let me execute a method specified
I am trying to create an application that makes a window (external to the
I'm trying to create an application that uses the iPhone MapView (under Google Code).
I am currently trying to create an Android application that loops Audio from the
Trying to create a small monitor application that displays current internet usage as percentage
I am trying to create a simple Android application that has a ActivityList of
I am learning Cocoa and trying to create an application for Mac that displays

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.