BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-10-2008, 12:12 AM   #1
nchreyes
New Member
 
Join Date: May 2008
Model: 8300
PIN: N/A
Carrier: Claro
Posts: 12
Default How write and read text files?

Please Login to Remove!

Hi guys, thanks for your support and patience, I am testing this code in order to write and read text files on my BB but when I compile I got this

String _PalabrasURL = "file:///SDCard/ahorcado/ahorcado.txt";
FileConnection fconn = (FileConnection)Connector.open(_PalabrasURL);

error message

symbol : variable Connector
location: class Ahorcado.Ahorcado
FileConnection fconn = (FileConnection)Connector.open(_PalabrasURL);
^

pointin to Connector.Open, I have include :
import javax.microedition.io.file.*;

Do I need something else in order to this code to work?

Thanks

Nelson
Offline  
Old 06-10-2008, 02:46 AM   #2
irlennard
Knows Where the Search Button Is
 
irlennard's Avatar
 
Join Date: Jan 2008
Location: Berlin
Model: 9000
Carrier: T-Mobile
Posts: 32
Default

You need to import javax.microedition.io.* too, for the Connector class.

-- Ian
Offline  
Old 06-10-2008, 11:41 AM   #3
nchreyes
New Member
 
Join Date: May 2008
Model: 8300
PIN: N/A
Carrier: Claro
Posts: 12
Default

thanks Ian, but now I getting this one

F:\BB\Ahorcado\Ahorcado.java:65: cannot find symbol
symbol : class Enumeration
location: class Ahorcado.Ahorcado
Enumeration e = FileSystemRegistry.listRoots();
^

any class missing? should I import another one?

Thanks for help me out.

Nelson
Offline  
Old 06-10-2008, 11:50 AM   #4
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Dude, look in the docs and find out which package these things are in. Then, import that package. This is how it goes with Java development.

Daily rant: Of course, if you were using a real IDE like Eclipse (basically !JDE) unresolved classes would be highlighted and you could just ctrl-shift-M to bring in the necessary imports.

BTW: Enumeration is in java.util. Please don't come back and ask about each unresolved symbol.
__________________
Do your homework and know how to ask a good question.
Offline  
Old 06-10-2008, 11:58 AM   #5
nchreyes
New Member
 
Join Date: May 2008
Model: 8300
PIN: N/A
Carrier: Claro
Posts: 12
Default

Quote:
Originally Posted by richard.puckett View Post
Dude, look in the docs and find out which package these things are in. Then, import that package. This is how it goes with Java development.

Daily rant: Of course, if you were using a real IDE like Eclipse (basically !JDE) unresolved classes would be highlighted and you could just ctrl-shift-M to bring in the necessary imports.

BTW: Enumeration is in java.util. Please don't come back and ask about each unresolved symbol.
Thanks , even Your are so rude with people that are learning, as I said in other thread I am student, this is my first aproach to java sure I am doing my homework, I have a lots of papers about classes , methods, and so far, thats what forums are for, persons like you that have a lot of experience helping people like me that is learning, so I will help in the future other people that needs help.

and Thanks again for you help hope it works I havent tried yet.

Nelson
Offline  
Old 06-10-2008, 12:08 PM   #6
nchreyes
New Member
 
Join Date: May 2008
Model: 8300
PIN: N/A
Carrier: Claro
Posts: 12
Default

As my friend from last reply suggest to do my homework here are packages I have include in my code, I dont know if are the right ones or I need more or less

import net.rim.device.api.ui.container.FlowFieldManager;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Status;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import java.util.*;

F:\BB\Ahorcado\Ahorcado.java:50: cannot find symbol
symbol : method open(java.lang.String)
location: interface javax.microedition.io.Connection
Connection.open(_PalabrasURL);

any Idea?

Thanks
Offline  
Old 06-10-2008, 12:34 PM   #7
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

Did you change "Connector" to "Connection"? The "open" method is in the "Connector" interface, not the "Connection" interface... Here's a sample. Let me know how it goes, amigo. If you're still getting problems please post all relevant code (enough to establish context, but not the whole app).

Code:
		
String fullPath = "file:///SDCard/foo.txt";
byte[] data = "foo".getBytes();

try {
    FileConnection fconn = (FileConnection) Connector.open(fullPath, Connector.READ_WRITE);

    if (fconn.exists()) {
        fconn.delete();
    }

    fconn.create();

    OutputStream os = fconn.openOutputStream();

    os.write(data);

    os.close();

    fconn.close();
}
catch (IOException e) {
    System.out.println("Oh noes!!1! " + e.toString());
}
__________________
Do your homework and know how to ask a good question.
Offline  
Old 06-10-2008, 12:53 PM   #8
nchreyes
New Member
 
Join Date: May 2008
Model: 8300
PIN: N/A
Carrier: Claro
Posts: 12
Default

Thanks Richard, I made some changes has you your code suggest here it is, but it looks a little different, and I got more doubts

boolean _sd=false; //to save result of SD validation
_sd=TieneTarjeta(); //here is a function to validate if a SD is inserted

FileConnection fconn; //a file connection
try
{
if (_sd) //if a SD is present, open or create a text file
{
String _PalabrasURL = "file:///SDCard/ahorcado/ahorcado.txt";
fconn = (FileConnection)Connector.open(_PalabrasURL);
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if (!fconn.exists())
Connector.open(_PalabrasURL); //this I am no sure, does it create it or just open it?

}
else
{
String _PalabrasURL = "file:///store/ahorcado/ahorcado.txt";
fconn = (FileConnection)Connector.open(_PalabrasURL);
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if (!fconn.exists())
Connector.open(_PalabrasURL);
}
}
catch (IOException ioe) //here jumps an error not find this symbol
{
//System.out.println("File error: " + ioe.toString());
}
fconn.close();
Offline  
Old 06-12-2008, 03:19 PM   #9
CJLopez
Thumbs Must Hurt
 
Join Date: May 2008
Model: 8700
PIN: N/A
Carrier: Telcel
Posts: 69
Default

Take a look at this

Getting Started with the FileConnection APIs
Offline  
Old 06-13-2008, 08:42 AM   #10
EmilieL
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: idk
Posts: 84
Default

Is it me or do I have the impression that, yes, this code is a J2ME one but Blackberrys don't support the APIs?
I've tried to import the packages but I always get errors...
I think it works with nokia cellphones though?
__________________
Stop telling me what it can do...
Show me how to make it do it!!!!
Offline  
Old 06-13-2008, 10:31 AM   #11
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

It's certainly supported on BlackBerry. It requires version 4.2.0 or higher though.
__________________
Do your homework and know how to ask a good question.
Offline  
Old 06-13-2008, 11:27 AM   #12
EmilieL
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 7100T
PIN: N/A
Carrier: idk
Posts: 84
Default

I've tried 4.2.1.. didn't work out...
It still can't find the package :O
I'll investigate on that...
Thanks for the info
__________________
Stop telling me what it can do...
Show me how to make it do it!!!!
Offline  
Old 06-15-2008, 11:58 AM   #13
nchreyes
New Member
 
Join Date: May 2008
Model: 8300
PIN: N/A
Carrier: Claro
Posts: 12
Default Text files read an Write

I fellows, I make code to work, but I still have some troubles handling text files and its resources, does any one can leadme to tutorial or code example how manage strings, text records, I will be really thanks.
I am trying to code a game for my son, I already did it on a windows app on C#, Hangup most of you must know it, you hava bank of words( my text file), app has to choose one randomly then show * on screen as many letters word has. I have not been able to count words on the text file, not even random a word, any Idea.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Johnson Controls T-5210-1007 Temperature Transmitter new picture

Johnson Controls T-5210-1007 Temperature Transmitter new

$439.99



Johnson Controls  Network Controller NU-NCM350-8 new picture

Johnson Controls Network Controller NU-NCM350-8 new

$5669.99



JOHNSON CONTROLS P545NCB-25C Lube Oil Control,Electronic,15 PSI picture

JOHNSON CONTROLS P545NCB-25C Lube Oil Control,Electronic,15 PSI

$90.00



Johnson Controls MS-NCE 2560-0 Metasys Network Control Engine picture

Johnson Controls MS-NCE 2560-0 Metasys Network Control Engine

$150.00



Johnson Controls Facility Explorer F4-CVM03050-0 (240) picture

Johnson Controls Facility Explorer F4-CVM03050-0 (240)

$400.00



Johnson Controls (240) F4-CGM04060-0 picture

Johnson Controls (240) F4-CGM04060-0

$149.00







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.