reading the contents of a file using readLine()

Hi everyone,

I am reading from a file using the readLine() method and assigning the value to a String. Now using readLine() i can read only a single line in the document. My file consists of several lines. how do i read from all the lines and assign it to a String? Please help.

{

File f =new File("mydata.txt");

FileInputStream fis =new FileInputStream(f);

BufferedInputStream bis =new BufferedInputStream(fis);

dis =new BufferedReader(new InputStreamReader(bis));

fileText = dis.readLine();

System.out.println(fileText);

}

Thanks

[845 byte] By [u4unnia] at [2007-10-2 7:36:00]
# 1
Sorry should have posted the query in Java Programming forrum, I am writing a java codeAnyways does anyone knows the answer?Thanks
u4unnia at 2007-7-16 21:17:42 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

read the lines in while loop, something like this

String txt = "";

String line = dis.readLine();

while(line != null)

{

txt += line;

dis.readLine();

}

kari-matti

kari-mattia at 2007-7-16 21:17:42 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
Thank u very much!!!
u4unnia at 2007-7-16 21:17:43 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4
hi , It was fine we can read the line with the help of the above code.What about when we want to display it on the device screen.Do we need seperate coding for implementing the alignment or seperate method was availableLakshman
lakshmanraoba at 2007-7-16 21:17:43 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

> hi ,

> It was fine we can read the line with the help of

> of the above code.What about when we want to display

> it on the device screen.

> Do we need seperate coding for implementing the

> the alignment or seperate method was available

>Lakshman

Hi Laksman,

I'm sorry, but don't understand what you mean by that.

kari-matti

kari-mattia at 2007-7-16 21:17:43 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

hi kari,

i meant, that the entire text will be display in a single line.ie see the following line

the line will be displayed as such,without any border to go to the next line

but we want

The line will be displayed

as such, without any

border to go to the

Next line

can you feel the difference ,

Lakshman

lakshmanraoba at 2007-7-16 21:17:43 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
hi,Ok, now I understand. first thing that comes to my mind is to save each of the lines to a String[] array. that way you can easilly print them out line by line.kari-matti
kari-mattia at 2007-7-16 21:17:43 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8

hi kari,

i Like your idea,but when the length of the screen was changed then we find odd with the text display.

At the same time we should consider the Scrolling option(When the text was too large to diaply in a single screen).

I hope that we have to write an seperate method manually to align the text.Because i have not found any method to do the alignment

Lakshman

lakshmanraoba at 2007-7-16 21:17:43 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 9

> I hope that we have to write an seperate method

> thod manually to align the text.Because i have not

> found any method to do the alignment

hi,

I think so too. You'll have to count the number of letters that fit on screen, and parse the String by that.

kari-matti

kari-mattia at 2007-7-16 21:17:43 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 10

hi kari,

I hav ewriten the code which will display the string line by line by calculating the string width and also considering the follwowing factors

1.Which Font we are using

2.calculating the width and height of the display screen

3.width of the letter and whether it will will fit in the remaining place

And with the points in mind i written the code

Thanks for your suggestions

lakshman

lakshmanraoba at 2007-7-16 21:17:43 > top of Java-index,Java Mobility Forums,Java ME Technologies...