Share on Google+Share on Google+

Nikhil J Mohite
About BufferedReader
3 Answer(s)      4 years and 7 months ago
Posted in : Java Beginners

I have created

FileInputStream fstream = new FileInputStream("E:\\TE MODULE\\Main Workspace\\OS PHASE 1\\input.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader bfr = new BufferedReader(new InputStreamReader(in));
for(int i=0;i<10;i++) {
String Str = bf.readline();

here is my 10th line. now i want to move to 1st line. what should i do ?


View Answers

September 7, 2012 at 12:27 PM

Here is a code that reads the first line of the text file.

class Modify 
        public static void main(String[] args) {
                String line = "";
                int lineNo;
                         FileInputStream fstream = new FileInputStream("c:/emp.txt"); 
                         DataInputStream in = new DataInputStream(fstream);
                         String str="";
                         BufferedReader bfr = new BufferedReader(new InputStreamReader(in)); 
                        for (lineNo = 1; lineNo <=10; lineNo++) {
                                if (lineNo == 1) {
                                        line = bfr.readLine();
                } catch (IOException e) {
                System.out.println("Line: " + line);

September 7, 2012 at 12:28 PM

Here is another code that reads the file and moves back to the first line of the file using seek() method of RandomAccessFile class.


public class ReadAccessFile{
  public static void main(String[] args) throws IOException{
      File f=new File("c:/emp.txt");
  RandomAccessFile rand = new RandomAccessFile(f,"r"); 
  int i=(int)rand.length();;
  for(int ct = 0; ct < i; ct++){
  byte b = rand.readByte();
  catch(IOException e)

January 31, 2013 at 3:07 PM

Please don't use DataInputStream to read text. Unfortunately this example gets repeated again and again so can you remove it from your example.

Related Tutorials/Questions & Answers:
About BufferedReader
About BufferedReader   I have created FileInputStream fstream..."); DataInputStream in = new DataInputStream(fstream); BufferedReader bfr = new BufferedReader(new InputStreamReader(in)); for(int i=0;i<10;i++) { String Str
BufferedReader  What is BufferedReader used for?   BufferedReader read text from a character-input stream, buffering characters so... IOException { BufferedReader in = new BufferedReader(new FileReader("C:/Hello.txt
Java IO BufferedReader
Java IO BufferedReader In this section we will discuss about the BufferedReader class in Java. BufferedReader class in package is used for read... be specified. In most of the purposes default size of buffer is used. BufferedReader
BufferedReader in java
BufferedReader in java In this section you will learn about BufferedReader..., this class contain BufferedReader under the package, it is advisable to use BufferedReader . BufferedReader br = new BufferedReader(new
Java bufferedreader
bufferedreader class? How bufferedreader can be used to read a file? Thanks   In Java the BufferedReader class is used to read the stream successfully with buffering. The BufferedReader class provides efficient reading from the input
Read bufferedreader
Read bufferedreader  Tell me the example of Read file using bufferedreader. Thanks   Read the tutorial Reading file using BufferedReader class. Thanks
Bufferedreader example
Bufferedreader example Here we have provided the best links for Bufferedreader class examples. You can use Bufferedreader class for buffering while reading... of Bufferedreader class Bufferedreader tutorial Bufferedreader Thanks
Why bufferedreader is used in java?
Why bufferedreader is used in java?  Hi, What is the use of BufferedReader class in Java? why bufferedreader is used in java? It will be great if anyone can give me the example code of BufferedReader class in java. Thanks
Scanner vs. BufferedReader
should use the BufferedReader class. Check the details at What is the fastest
convert it to BufferedReader class
convert it to BufferedReader class  import java.util.*; public class method { static Scanner console = new Scanner (; public static...; double average; BufferedReader br=new BufferedReader(new InputStreamReader
Convert InputStream to BufferedReader
Convert InputStream to BufferedReader   ... Inputstream to Bufferedreader. The class ... a input stream. BufferedReader class provides efficient way
what is the default buffer size for bufferedreader
is the default buffer size for bufferedreader? Is there any example of reading the big... of the BufferedReader class is 8192 chars, which is sufficient for general programming
What is the use of BufferedReader in Java program?
Learn about BufferedReader class and understand "What is the use of BufferedReader in Java program?" In this article I will explain you the benefits and uses... Search tutorials about BufferedReader Why
BufferedReader in Java
BufferedReader in Java BufferedReader in Java is used to to read characters.... BufferedReader class in Java is also used to read the data in buffer. Here we will show how to read line by line data from a file using BufferedReader
How To Read File In Java with BufferedReader
How To Read File In Java with BufferedReader class - example code This tutorial shows you how you can read file using BufferedReader class in your program. This tutorial is using the BufferedReader class for reading simple text file
How to Read a file line by line using BufferedReader?
How to Read a file line by line using BufferedReader?  Hello Java... and found that BufferedReader can be used. So, help me and let's know How to Read a file line by line using BufferedReader, efficiently and using less memory
about predefine classes.....
about predefine classes.....  how we know that the class used in your given examples are predefind and from where we get info. about other predefine classes. we need explanation about examples given by you for java beginners
About struts
About struts  How will we configure the struts
About Java
About Java  Hi, Can anyone tell me the About Java programming language? How a c programmer can learn Java development techniques? Thanks   Hi, Read about java at Thanks
about java
about java  how to get the value from the user like c, c++ program pls explain with example for me
About jsp
About jsp  Read Excel data using JSP and update MySQL databse
about jquery
about jquery  i want to put already made dropdown menu code which is in internet into my website.but how to put
about connectivity
about connectivity  hello i am basavaraj,will any one tell me how to use hibernate in struts.   Please visit the following link: Struts Hibernate Integration
About Main
About Main  can u create the object of one interface ? But i can able to create the abstract class through anonimous inner class.similarly can i
About Main
About Main  can u create the object of one interface ? But i can able to create the abstract class through anonimous inner class.similarly can i
ABOUT Jtable
ABOUT Jtable  My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql . How can retrive Data in Jtable from Mysql Database in Net Beans
about java1
about java1  Sir, i want to know how we develop 3d button ,lable,textfield etc. in java . sir plz give one program as well Thank you
About Java2
About Java2  sir i want to a develop one text editor but the problem is that i m not able to save our file as text formet or any formet Sir plz guide me
About Project
About Project  Hello friends i want to make a project on face reconization this is my first projct so please help me that how i start my projct please tell me some working with image codeing. thanks
about session
about session  hey i want to insert userid and username of the user who have currently loggedin in servlet using prepared statement   Please visit the following link:
About Constructor
About Constructor  How many objects are create when this code will execute... String string = new String("Java is best Lang."); tell me the number of object of string which will create . All are those are eligible for garbage
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized


Advertisement null