473,395 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

problem with read line by line using BufferReader class

hi!
I am trying to read file line by line using BufferReader class.Following I have written to read but some how for few of the file it is not reading the whole file. Can any help me to resolve this or suggest me the best apporch to read line by line from given file ?


try {
br = FileRead.readTOLine(path ,filename);
while ((line =br.readLine()) != null){
line = line.toUpperCase().trim();
ltrim(line);
rtrim(line);
System.out.println(line);
System.out.flush();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}




public class FileRead {



/* Pass filename and path as input
* Return BufferedReader
*/
public static BufferedReader readTOLine(String path, String filename) throws IOException{

BufferedReader br= new BufferedReader (new FileReader (path + filename));

//br.close();
return br;
}

/*
* Pass Reader as input
* Return String
* */
Jun 18 '07 #1
4 5026
prometheuzz
197 Expert 100+
hi!
I am trying to read file line by line using BufferReader class.Following I have written to read but some how for few of the file it is not reading the whole file. Can any help me to resolve this or suggest me the best apporch to read line by line from given file ?
...
Are there excpetion thrown? If so, which ones?
Could you post an example of a file that is partially read? (if not too big)
Jun 18 '07 #2
JosAH
11,448 Expert 8TB
I normally read a file line by line like this:

Expand|Select|Wrap|Line Numbers
  1. public void readFile(String name) throws IOException {
  2.    BufferedReader br= new BufferedReader(new FileReader(name));
  3.    String line;
  4.    while ((line= br.readLine()) != null)
  5.       processLine(line);
  6.    br.close();
  7. }
Use it the way you want.

kind regards,

Jos
Jun 18 '07 #3
r035198x
13,262 8TB
I normally read a file line by line like this:

Expand|Select|Wrap|Line Numbers
  1. public void readFile(String name) throws IOException {
  2.    BufferedReader br= new BufferedReader(new FileReader(name));
  3.    String line;
  4.    while ((line= br.readLine()) != null)
  5.       processLine(line);
  6.    br.close();
  7. }
Use it the way you want.

kind regards,

Jos
Notice how he wrapped his code in code tags ...
Jun 18 '07 #4
JosAH
11,448 Expert 8TB
Notice how he wrapped his code in code tags ...
I've always been a fine example to humanity ;-)

kind regards,

Jos
Jun 18 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: RP2001 | last post by:
I've serialized in various variables of various types (mainly CString, int, double) into an instantiated MFC CArchive class and saved it as a binary file. I am able to open the binary file and...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
12
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an...
12
by: Julian | last post by:
Hi, I am having problems with a function that I have been using in my program to read sentences from a 'command file' and parse them into commands. the surprising thing is that the program works...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.