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



Home Answers Viewqa Java-Beginners About BufferedReader

Have Programming Question? Ask it here!
 
 
 


Nikhil J Mohite
About BufferedReader
3 Answer(s)      2 years 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 jsp
About jsp  Read Excel data using JSP and update MySQL databse
about java
about java  how to get the value from the user like c, c++ program pls explain with example for me
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 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 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 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 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 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 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
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 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 Database
About Database  in my database i enter the date of birth as Birth_Date date but i dont know in which format we can mention the date of birth   In MySQL database, date should be entered in the following format: yyyy-mm
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 a program
about a program  hi can anyone suggest program for this question.. it wil really be helpful.its based on *servlet programming* 1. First page should display a dropdown of mathematical operation (Add, Subtract, Multiply, Divide
About java
About java   how we insert our database data into the jTable in java or how we show database content into the JTable in java   Hi Friend, Try the following code: import java.io.*; import
about form
about form  how to dynamically increase the textbox in the 2nd form when i gave any value in textbox of form1 . if i gave 5 in the textbox of form1 , totally 5textbox have to be created in form2.   import javax.swing.
about java - Java Beginners
about java  hello, being a begineer in Java i would like know that as we read the value entered by user through cin>> in c++ how we did... the methods of BufferedReader class, Scanner class, StreamTokenizer class
About this tutorial
About this tutorial     ... for their organization.   Information about setting up Simple Cart Information about how features are implemented and explains basic API related
About MYSQL
About MYSQL  is it possible to upload the video on mysql database   1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>
SCJP Module-10 Question-10
FileReader("new.txt"); BufferedReader br = new (2) Place code here...) FileReader  (Y) br.readLine() (Z) BufferedReader(fr) Options: (A) 1-X
About the project
About the project       Shopping cart application is an open source project written in Java ,Struts and Hibernate. This  helps  people that want to develop
About RoseIndia.net
About RoseIndia.Net RoseIndia.Net  is global services company that understands businesses and aims to deliver value to its customers through its software solutions and services. We are providing
About Webservice - WebSevices
About Webservice  I wanted to know about WebServices
Question about "Insert text file data into Database"
Question about "Insert text file data into Database"  Hey I was reading the tutorial "Insert text file data into Database", (awesome btw), and noticed that both a FileInputStream, a DataInputStream and a BufferedReader
about J2EE. - Java Beginners
about J2EE.  I know only core Java ... what chapter I will be learn to know about J2EE
about enum - Java Beginners
about enum  hi all, please tell me about "enum" and explain with example. And its use in OOP. Thanks
about jboss - Java Beginners
about jboss  can you please explain about jboss...how to deploy,where the temp and lock is there...total information about jboss to use in java message services(JMS
doubt about J2EE connetivity
doubt about J2EE connetivity  steps to connect J2EE components with MYSQL
about google map
about google map  how to add google map in website
about google map
about google map  how to add google map in website
Query about bioinformatics
Query about bioinformatics  Wat is ment by spring? How it useful in bioinformatics
Advertisements
 

 

 

DMCA.com