BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-21-2011, 10:31 AM   #1 (permalink)
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
Post Thanks: 5
Thanked 0 Times in 0 Posts
Default Read String in File text.

Please Login to Remove!

fconn = (FileConnection) Connector.open("file:///D:/IP.txt", Connector.READ);

in "file:///D:/IP.txt" have String "LocalHost"

How to read string and show message "LocalHost" in my app

please,
Offline  
Old 11-21-2011, 03:13 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default Re: Read String in File text.

Call FileConnection.openInputStream() to obtain a stream, then read the stream.
Offline  
Old 11-21-2011, 10:27 PM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
Post Thanks: 3
Thanked 5 Times in 5 Posts
Default Re: Read String in File text.

Like in the earlier reply, once you have the connection, you could get the InputStream. You can then use the IOUtilities class provided by RIM to read the whole content into an array.

InputStream in = fconn.openInputStream();
byte[] data = IOUtilities.streamToBytes( in );

You could then set the data in a StringBuffer,

StringBuffer sb = new StringBuffer(data.length);
sb.append(data);

For small data file this would be an easier way to go.
Offline  
The Following User Says Thank You to berryapp For This Useful Post:
bankkab (11-23-2011)
Old 11-23-2011, 12:27 AM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
Post Thanks: 3
Thanked 5 Times in 5 Posts
Thumbs up Re: Read String in File text.

Quote:
Originally Posted by berryapp View Post
Like in the earlier reply, once you have the connection, you could get the InputStream. You can then use the IOUtilities class provided by RIM to read the whole content into an array.

InputStream in = fconn.openInputStream();
byte[] data = IOUtilities.streamToBytes( in );

You could then set the data in a String,

String = new String(data.); // need to use String

For small data file this would be an easier way to go.
String = new String(data.); // need to use String
Offline  
The Following User Says Thank You to berryapp For This Useful Post:
bankkab (11-23-2011)
Old 11-23-2011, 01:48 AM   #5 (permalink)
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
Post Thanks: 5
Thanked 0 Times in 0 Posts
Default Re: Read String in File text.

Quote:
Originally Posted by berryapp View Post
String = new String(data.); // need to use String
try {
fconn = (FileConnection) Connector.open("file:///D:/IP.txt", Connector.READ);
//is = fconn.openDataInputStream();
// data = IOUtilities.streamToBytes(is);
InputStream in = fconn.openInputStream();
byte[] data = IOUtilities.streamToBytes(in);
String sss = new String(data);
oxi = new LabelField(sss);
}



catch (IOException e)
{
System.out.println(e.getMessage());
}
add(oxi);


Build Complete but....In my App is Error !

Helpme please
Offline  
Old 11-23-2011, 01:18 PM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
Post Thanks: 3
Thanked 5 Times in 5 Posts
Exclamation Re: Read String in File text.

Quote:
Originally Posted by bankkab View Post
try {
fconn = (FileConnection) Connector.open("file:///D:/IP.txt", Connector.READ);
//is = fconn.openDataInputStream();
// data = IOUtilities.streamToBytes(is);
InputStream in = fconn.openInputStream();
byte[] data = IOUtilities.streamToBytes(in);
String sss = new String(data);
oxi = new LabelField(sss);
}



catch (IOException e)
{
System.out.println(e.getMessage());
}
add(oxi);


Build Complete but....In my App is Error !

Helpme please
You need to provide little bit more information. I believe you are saying that you can build fine, but you get error while running the app? What error message you exactly see. You could run your app in debug mode and add break point at certain line based on the error that you see.
Offline  
Old 11-24-2011, 09:52 AM   #7 (permalink)
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
Post Thanks: 5
Thanked 0 Times in 0 Posts
Default Re: Read String in File text.

it shows debug

source code is not available
source code is not available
source code is not available
source code is not available
source code is not available

File system error (1003)

when i click in my app
Offline  
Old 11-24-2011, 10:55 AM   #8 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
Post Thanks: 3
Thanked 5 Times in 5 Posts
Default Re: Read String in File text.

Quote:
Originally Posted by bankkab View Post
it shows debug

source code is not available
source code is not available
source code is not available
source code is not available
source code is not available

File system error (1003)

when i click in my app
Did you put break point at some lines within the class file that you created? The debugger should be able to find the source from your class
Offline  
Old 11-24-2011, 11:51 AM   #9 (permalink)
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
Post Thanks: 5
Thanked 0 Times in 0 Posts
Default Re: Read String in File text.

Can you Give me a sample code for

read string in my Text file please
Offline  
Old 11-24-2011, 08:33 PM   #10 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
Post Thanks: 3
Thanked 5 Times in 5 Posts
Default Re: Read String in File text.

Quote:
Originally Posted by bankkab View Post
Can you Give me a sample code for

read string in my Text file please
Here is a method. After you start the simulator, first save a file temp.txt making sure that there is a file by that name and appropriate location.
---------------------------------------------------------
public String readFile() {
FileConnection fc = null;
String fileContent = "";
try {
fc = (FileConnection)Connector.open("file:///store/home/user/temp.txt");
if ( (fc==null) || !fc.exists()){
return "File does not exist";
}

InputStream in = fc.openInputStream();
byte[] data = IOUtilities.streamToBytes( in );
fileContent = new String(data);

in.close();
fc.close();
} catch (Throwable t) {

}
return fileContent;
}
Offline  
The Following User Says Thank You to berryapp For This Useful Post:
bankkab (11-25-2011)
Old 11-25-2011, 01:35 AM   #11 (permalink)
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
Post Thanks: 5
Thanked 0 Times in 0 Posts
Default Re: Read String in File text.

here this code

class Connect extends MainScreen {



Connect() {


FileConnection fc = null;
String fileContent = "";
try {
fc = (FileConnection)Connector.open("file:///D:/IP.txt");
if ( (fc==null) || !fc.exists()){
return "File does not exist";
}

InputStream in = fc.openInputStream();
byte[] data = IOUtilities.streamToBytes(in);
fileContent = new String(data);

in.close();
fc.close();
} catch (Throwable t) {

}
return fileContent;
}

}

it error " cannot return a value from method whose result type is void "

where is a void i don't declare a void function
Offline  
Old 11-25-2011, 10:28 AM   #12 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
Post Thanks: 3
Thanked 5 Times in 5 Posts
Default Re: Read String in File text.

Quote:
Originally Posted by bankkab View Post
here this code

class Connect extends MainScreen {



Connect() {


FileConnection fc = null;
String fileContent = "";
try {
fc = (FileConnection)Connector.open("file:///D:/IP.txt");
if ( (fc==null) || !fc.exists()){
return "File does not exist";
}

InputStream in = fc.openInputStream();
byte[] data = IOUtilities.streamToBytes(in);
fileContent = new String(data);

in.close();
fc.close();
} catch (Throwable t) {

}
return fileContent;
}

}

it error " cannot return a value from method whose result type is void "

where is a void i don't declare a void function
Since your method returns String, so you need to have the method declaration accordingly, i.e.,
String Connect() { //instead of Connect() {
Offline  
Old 11-25-2011, 11:21 AM   #13 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default Re: Read String in File text.

Well, actually, constructors can't return a value at all.
__________________
My other Blackberry is a PlayBook.
Offline  
The Following User Says Thank You to hrbuckley For This Useful Post:
berryapp (11-25-2011)
Old 11-25-2011, 12:33 PM   #14 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
Post Thanks: 3
Thanked 5 Times in 5 Posts
Default Re: Read String in File text.

Quote:
Originally Posted by hrbuckley View Post
Well, actually, constructors can't return a value at all.
sorry! I didn't notice that. My original suggested method (public String readFile()) was not a constructor, so that was in my mind while I was typing.
Offline  
Old 11-25-2011, 12:37 PM   #15 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
Post Thanks: 3
Thanked 5 Times in 5 Posts
Default Re: Read String in File text.

Quote:
Originally Posted by berryapp View Post
Since your method returns String, so you need to have the method declaration accordingly, i.e.,
String Connect() { //instead of Connect() {
Since you placed the code within a constructor, remove the return statement.
Offline  
Old 11-28-2011, 12:37 AM   #16 (permalink)
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
Post Thanks: 5
Thanked 0 Times in 0 Posts
Default Re: Read String in File text.

In netbean i'm use Class Scanner for read string

but In Blackberry Jde not have class Scanner
Offline  
Old 12-07-2011, 05:36 PM   #17 (permalink)
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
Post Thanks: 3
Thanked 5 Times in 5 Posts
Exclamation Re: Read String in File text.

Quote:
Originally Posted by bankkab View Post
In netbean i'm use Class Scanner for read string

but In Blackberry Jde not have class Scanner
Please note that, you can't use many of the APIs that are available in the later version of Java. I think anything after jdk 1.3 is a NO NO!
__________________
HUB++ Rocks!
Offline  
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads for: Read String in File text.
Thread Thread Starter Forum Replies Last Post
sorting a text file rashmi.rrb Developer Forum 1 11-17-2010 09:44 AM
Error message after sync aandina General 8900 Series Discussion - Javelin 2 02-01-2010 12:22 PM
File Manager Pro v1.5 Released TerraMobility Aftermarket Software 2 09-12-2009 08:19 PM
A problem of read file streamh Developer Forum 4 08-13-2007 09:21 PM
Having trouble synchronizing contacts between Pearl and Outlook dfarrales General 8100 Series Discussion - Pearl 7 04-09-2007 02:03 AM





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