×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    28

    Import and export using txt file?

    Hello,

    I want to use txt file to import and export data between phone and PC. I need some method, which will read one line from the txt file, return it as String, and next time calling this method would read the next line, and so on, till end of file. I would store each line in separate record in record store. And for export I need method which will do the opposite, take a String and write one line in the txt file.

    Where could I find more informations and samples how to do it?

    Another question, how could I hardcode the path to the txt file, so that it would work on any phone? Something like C:\iotext.txt ?

    Thank you

  2. #2
    Regular Contributor
    Join Date
    Aug 2008
    Location
    Bournemouth, UK
    Posts
    65

    Re: Import and export using txt file?

    well for taking the datat out i would read the txt file in one go... i would put each line into an array of strings and return that, other than that i believe you could pass the open stream into the method and from there extract the nextLine() method from the open stream object and return that string. again same goes for putting lines into the text file. pass the array into the method which loops through the elements adding lines to the text file as you go or failing that pass the open stream object and string line to the method each time. and if you use an array you can easily loop through it adding to the record store.

    i would show you some code but its simple stuff and im at work hope it helps.

    and with opening the text file i think there is something available that can let you open a resource stream from the same dir as the class your running, i don't know if this is the same for ME so id google it a bit...

    InputStream streamObject = this.getClass().getResourceAsStream("/TEXTFILEHERE.TXT");

    check up on what the InputStream class can and cant do and weather you can use it in mobile edition but there you go!
    Last edited by rooossone; 2008-08-28 at 15:57.
    Made With Caffiene And Sleepless Nights

  3. #3
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Import and export using txt file?

    Hi guys,

    Actually "getResourceAsStream()" won't work as expected. It reads a file from the root of the JAR file (not from filesystem), so in this scenario it would return null.

    My suggestion:

    - Server side: Use a BufferedReader and its readLine() method to read the file line by line, save it on a Vector or array.
    - Client side: No buffered reader, you have to use InputStreamReader or any other I/O classes for reading and splitting the string by "\n" if needed. Save the file using FileConnection API, using one of the "safe" paths: http://www.forum.nokia.com/document/...79F5BE26E.html.

    Daniel

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    28
    Thank you, I will try it.

    BTW is there any easier way how to synchronize data between desktop and phone?

  5. #5
    Regular Contributor
    Join Date
    Aug 2008
    Location
    Bournemouth, UK
    Posts
    65

    Re: Import and export using txt file?

    have you thought about using xml?

    its a slightly better than using plain text because it allows you to create a data structure, one that could immitate the fields and tables you have in a database on your pc for example, either way it allows for uniformity and expandability, you wont necessarily have to change code if you make changes or add to an xml document
    Made With Caffiene And Sleepless Nights

Similar Threads

  1. how dll function be export to lib and import by dso
    By eroslin in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2008-06-19, 01:30
  2. Contacts fields order??
    By timatima in forum Symbian C++
    Replies: 1
    Last Post: 2007-06-08, 13:51
  3. Carbide developer wont import EXPORT commands from EXPORT.MAKE
    By jimgilmour1 in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 3
    Last Post: 2006-10-26, 06:27
  4. PKG file, SISAR & Symbian Signed
    By heuven in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2006-01-12, 09:16
  5. How to import / export from PC Suite 4.5
    By stephen ford in forum General Development Questions
    Replies: 0
    Last Post: 2004-03-15, 11:18

Posting Permissions

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