BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 11-21-2011, 10:31 AM   #1
bankkab
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
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
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
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
berryapp
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
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  
Old 11-23-2011, 12:27 AM   #4
berryapp
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
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  
Old 11-23-2011, 01:48 AM   #5
bankkab
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
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
berryapp
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
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
bankkab
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
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
berryapp
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
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
bankkab
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
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
berryapp
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
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  
Old 11-25-2011, 01:35 AM   #11
bankkab
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
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
berryapp
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
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
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default Re: Read String in File text.

Well, actually, constructors can't return a value at all.
__________________
My other Blackberry is a PlayBook.
Offline  
Old 11-25-2011, 12:33 PM   #14
berryapp
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
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
berryapp
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
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
bankkab
New Member
 
Join Date: Nov 2011
Model: 7100T
PIN: N/A
Carrier: Bike
Posts: 13
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
berryapp
Knows Where the Search Button Is
 
Join Date: Nov 2011
Model: 9800T
PIN: N/A
Carrier: Rogers Canada
Posts: 34
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



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

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 07:19 PM
A problem of read file streamh Developer Forum 4 08-13-2007 08:21 PM
Having trouble synchronizing contacts between Pearl and Outlook dfarrales General 8100 Series Discussion - Pearl 7 04-09-2007 01:03 AM


Automation Direct Potentiometer Part No. ECX2300-10K picture

Automation Direct Potentiometer Part No. ECX2300-10K

$30.00



Takeuchi Potentiometer 1911514843 picture

Takeuchi Potentiometer 1911514843

$81.42



Dynapac Potentiometer Kit 4812158159 picture

Dynapac Potentiometer Kit 4812158159

$731.98



Potentiometer ASS'Y Knob 22U-06-22420 For Komatsu PC220LC-7 PC360-7 Excavator picture

Potentiometer ASS'Y Knob 22U-06-22420 For Komatsu PC220LC-7 PC360-7 Excavator

$49.00



10 turn Potentiometer 3590S Wirewound Variable Resistor Precision multi-turn POT picture

10 turn Potentiometer 3590S Wirewound Variable Resistor Precision multi-turn POT

$51.49



US Stock 10 Units 100K B100K OHM Linear Taper Rotary Potentiometer POT Red Knob picture

US Stock 10 Units 100K B100K OHM Linear Taper Rotary Potentiometer POT Red Knob

$9.49







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