Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners About BufferedReader
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Nikhil J Mohite
About BufferedReader
3 Answer(s)      2 years and 3 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 ?


Advertisement
View Answers

September 7, 2012 at 12:27 PM


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

import java.io.*;
class Modify 
{
        public static void main(String[] args) {
                String line = "";
                int lineNo;
                try{
                         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();
                                } 
                                str=bfr.readLine();
                        }
                } catch (IOException e) {
                        e.printStackTrace();
                }
                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.

 import java.io.*;

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


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
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
Advertisements
Java IO BufferedReader
Java IO BufferedReader In this section we will discuss about the BufferedReader class in Java. BufferedReader class in java.io 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 java.io.BufferedReader...., 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
convert it to BufferedReader class
convert it to BufferedReader class  import java.util.*; public class method { static Scanner console = new Scanner (System.in); 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. java.io. 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 is used to to read characters, arrays, lines and File... can change the buffer size or can use default size. BufferedReader class in Java... by line data from a file using BufferedReader. BufferedReader Constructor
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 http://www.roseindia.net/java. 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: http://www.devmanuals.com/tutorials/java/servlet
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
About Jsp
About Jsp  Hello sir, I am developing online Quiz project in jsp using MySql Database. I want to know that How I will show Questions from database One by One on Same page and also want to calculate Result for the User
 

 

 

DMCA.com