×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    5

    Help on reading and writing into the same CSV File

    Hi, could I have some help on this J2ME application. I am trying to read a CSV file and then write into it by either editing a line or inserting a new line.
    This is my current test code.

    FileConnection filecon =
    (FileConnection)Connector.open("file:///root1/test.csv",Connector.READ_WRITE);

    if(!filecon.exists()) {
    filecon.create();
    }
    OutputStream os = filecon.openOutputStream();
    PrintStream output=new PrintStream(os);
    output.println("This is a test" + "," + "file");
    os.close();



    However, I noticed that when I run my J2ME application, a new temp folder is being created each time so a new test.csv is being created each time. This way, I am not being able to access the test.csv file I had put in the root folder which is here: "j2mewtk\2.5.2\appdb\temp.DefaultColorPhone116\filesystem\root1"

    Please help me, thanks a lot in advance
    JEEVA
    Last edited by Veron_4; 2009-12-23 at 06:18.

  2. #2
    Super Contributor
    Join Date
    Apr 2009
    Posts
    572

    Re: Help on reading and writing into the same CSV File

    your path looks suspecting what is temp. I never found it any files system both in WTK 2.5 and netbeans 5.5.1

    "j2mewtk\2.5.2\appdb\temp.DefaultColorPhone116\filesystem\root1"
    I found this

    "appdb\DefaultColorPhone\filesystem\root1"
    Regards,
    Saurabh

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    5

    Re: Help on reading and writing into the same CSV File

    Hi, thanks for trying to help. In the j2mewtk\2.5.2\appdb folder, a new "temp.DefaultColorPhoneXXX" folder is created. XXX refers to a number which increases by 1 each time I run the application

    So a new 'test/csv' file is created in the
    "j2mewtk\2.5.2\appdb\temp.DefaultColorPhone116\filesystem\root1"
    folder instead of looking at the
    "j2mewtk\2.5.2\appdb\DefaultColorPhone\filesystem\root1"
    folder where the original CSV file is located.

    You won't be able to see the temp folder in your PC as it's only created during runtime

  4. #4
    Super Contributor
    Join Date
    Apr 2009
    Posts
    572

    Re: Help on reading and writing into the same CSV File

    Ok it well I used the 2.5.2 earlier but never found such issues my luck afaik its buggy u must try for final release i.e. 2.5 only and try one thing more place any file in your filesystem manually and try to access it through your code if you succed in it then try for writing it
    Regards,
    Saurabh

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    5

    Re: Help on reading and writing into the same CSV File

    I did try to manually create the csv file and access it. But problem is that it keeps creating a new one

  6. #6
    Super Contributor
    Join Date
    Apr 2009
    Posts
    572

    Re: Help on reading and writing into the same CSV File

    PHP Code:
    FileConnection fc null;
                
    InputStream ips null;
                try
                {
                    
    String songTitle theFile.substring(theFile.lastIndexOf('/')+1,theFile.lastIndexOf('.'));
                    
    fields2[1].setText(songTitle.toUpperCase());
                    
    fields2[1].invalidating();
                    
    titleText songTitle;
                    
    saved true;
                    
    fc = (FileConnection)Connector.open("file:///" theFile Connector.READ_WRITE);
                    
    ips fc.openInputStream();
                    
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    
    byte[] buffer = new byte[(int)fc.fileSize()];
                    while (
    true)
                    {
                        
    int bytesRead ips.readbuffer0buffer.length );
                        if (
    bytesRead == -1)
                            break;
                        
    byteArrayOutputStream.writebuffer0bytesRead );
                    }
                    
    byteArrayOutputStream.flush();
                    
    byte[] result byteArrayOutputStream.toByteArray();
                    
    byteArrayOutputStream.close();
                    
    String resultString = new String(result); 
    try this code please edit it some its long code I gave you only reading the file try this
    Regards,
    Saurabh

  7. #7
    Registered User
    Join Date
    Dec 2009
    Posts
    5

    Re: Help on reading and writing into the same CSV File

    I tried that, it does the same thing. A new temporary folder is being created instead of looking for the file I have.

  8. #8
    Super Contributor
    Join Date
    Apr 2009
    Posts
    572

    Re: Help on reading and writing into the same CSV File

    then I suspect its your toolkit problem change it and gave a try
    Regards,
    Saurabh

  9. #9
    Registered User
    Join Date
    Dec 2009
    Posts
    5

    Re: Help on reading and writing into the same CSV File

    Sorry, still not working.. Everytime I startup the application, it automatically goes into the storage root and creates a new temp folder.

    Is there any way, I can change this?

  10. #10
    Super Contributor
    Join Date
    Apr 2009
    Posts
    572

    Re: Help on reading and writing into the same CSV File

    Quote Originally Posted by Veron_4 View Post
    Sorry, still not working.. Everytime I startup the application, it automatically goes into the storage root and creates a new temp folder.

    Is there any way, I can change this?
    k try this ,this is my last resort otherwise I cant figure out what the problem is
    PHP Code:
    FileConnection filecon =
    (
    FileConnection)Connector.open("file:///root1/test/test.csv",Connector.READ_WRITE);

    if(!
    filecon.exists()) {
    filecon.create();
    }
    else
    {
    filecon.delete();
    filecon.create();
    }
    OutputStream os filecon.openOutputStream();
    PrintStream output=new PrintStream(os);
    output.println("This is a test" "," "file");
    os.close(); 
    and create test folder in your root1 directory
    Regards,
    Saurabh

Similar Threads

  1. Reading and writing to file
    By rkuppala in forum Symbian
    Replies: 6
    Last Post: 2008-03-13, 09:59
  2. File reading & writing help, wav file redaing help
    By shubhamlahoti in forum Mobile Java General
    Replies: 6
    Last Post: 2007-06-27, 09:07
  3. reading from a file and writing to another file
    By ibraheemJazba in forum Symbian
    Replies: 3
    Last Post: 2007-03-08, 11:50
  4. Reading and Writing to file
    By rkuppala in forum Symbian
    Replies: 1
    Last Post: 2004-08-03, 15:17

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×