Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Networking problem

Reply
Thread Tools

Networking problem

 
 
JONESEY
Guest
Posts: n/a
 
      11-30-2003
Im trying to get a text file from a server and load it into a 2
dimensional array. So i came up with the follwoing method. The file is
a table using "|" to indicate the end of a cell and "¬" to indicate
the end of a row. I use if statements to find these but the if
statements done seem to to execute!! Any ideas?

J

void getFile(String url) throws IOException {
int x = 0;
int y = 0;
StreamConnection c = null;
InputStream s = null;
StringBuffer b = new StringBuffer();
TextBox t = null;
String temp;
try {
c = (StreamConnection)Connector.open(url);
s = c.openInputStream();
int ch;
while((ch = s.read()) != -1) {
temp = String.valueOf((char)ch);
if (temp == "|"){
fileArray[x][y] = b.toString();

x++;
b = null;
}
else if (temp == "¬"){
fileArray[x][y] = b.toString();
x = 0;
y++;
b = null;

}
else{
b.append((char) ch);
t = new TextBox("Fetch Page", b.toString(), 1024,
0);
}
}
 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      11-30-2003
JONESEY
> Im trying to get a text file from a server and load it into a 2
> dimensional array. So i came up with the follwoing method. The file is
> a table using "|" to indicate the end of a cell and "¬" to indicate
> the end of a row. I use if statements to find these but the if
> statements done seem to to execute!! Any ideas?
>
> J
>
> void getFile(String url) throws IOException {
> int x = 0;
> int y = 0;
> StreamConnection c = null;
> InputStream s = null;
> StringBuffer b = new StringBuffer();
> TextBox t = null;
> String temp;
> try {
> c = (StreamConnection)Connector.open(url);
> s = c.openInputStream();
> int ch;
> while((ch = s.read()) != -1) {
> temp = String.valueOf((char)ch);
> if (temp == "|"){
> fileArray[x][y] = b.toString();


Some interesting code! First you have to decide whether you're
going to using Strings or chars. Based on your coercion of an
int into a String containing a single character, it appears
that you're going the String route. But then you do the oddest
comparison! If you're checking for String equivalance then you
should use temp.equals( "|" ). Your code just checks whether the
strings share the same memory location. (They don't)
That being said, have you considered using char instead? That
would make the if statement look like this:
if( '|' == (char) ch ) {
A bit less overhead than what you've got currently.

 
Reply With Quote
 
 
 
 
JONESEY
Guest
Posts: n/a
 
      11-30-2003
Yeah sorry it is intresting code. I have now got it doing it via the
char comparison but its not doing anything!! The program just stops!!
Was there anything e;se that jumped out at you

On Sun, 30 Nov 2003 13:11:39 -0500, Sudsy <>
wrote:
>Some interesting code! First you have to decide whether you're
>going to using Strings or chars. Based on your coercion of an
>int into a String containing a single character, it appears
>that you're going the String route. But then you do the oddest
>comparison! If you're checking for String equivalance then you
>should use temp.equals( "|" ). Your code just checks whether the
>strings share the same memory location. (They don't)
>That being said, have you considered using char instead? That
>would make the if statement look like this:
> if( '|' == (char) ch ) {
>A bit less overhead than what you've got currently.


 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      11-30-2003
JONESEY
> Yeah sorry it is intresting code. I have now got it doing it via the
> char comparison but its not doing anything!! The program just stops!!
> Was there anything e;se that jumped out at you


On second visit, it appears that the very first time you encounter
a character which isn't special (i.e. the NOT or the OR) you create
a new TextBox. I don't know where the code for setVisible( true )
is located but it looks like that constructor doesn't belong INSIDE
the loop. Shouldn't it only be instantiated AFTER the loop, i.e.
after you've read the entire input?

 
Reply With Quote
 
JONESEY
Guest
Posts: n/a
 
      11-30-2003
the problem lies with the b = null; Is there anyway to delete all teh
characters from a String buffer?

 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      11-30-2003
JONESEY
> the problem lies with the b = null; Is there anyway to delete all teh
> characters from a String buffer?
>


b.setLength( 0 );

 
Reply With Quote
 
JONESEY
Guest
Posts: n/a
 
      11-30-2003
A BIG THANKS!!!!

J

On Sun, 30 Nov 2003 16:04:03 -0500, Sudsy <>
wrote:

>JONESEY
>> the problem lies with the b = null; Is there anyway to delete all teh
>> characters from a String buffer?
>>

>
>b.setLength( 0 );


 
Reply With Quote
 
 
 
Reply

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet networking , group networking,business leads,new business opportunities,like having many sales peoples elie Computer Support 0 08-18-2007 10:12 AM
networking two pc together with wireless networking ? Andy Wireless Networking 4 02-26-2007 06:02 PM
PROBLEMS WITH NETWORKING - NEW TO NETWORKING =?Utf-8?B?QUJTUE9QVVA=?= Wireless Networking 2 03-23-2005 08:31 AM
[Reminder] Online chat with Networking & Devices VP about Networking in Longhorn Eddy Malik [MSFT] Wireless Networking 0 03-22-2005 03:27 AM
networking 2 pc with a networking hub and 1 internet connection barry crowley Computer Support 20 02-27-2004 05:09 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57