Results 1 to 4 of 4
- 01-04-2012, 01:59 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
reading particular line from textfile file
its copying and printing text in console from the text file but don't know how to copy particular lines from the file and print them. I have attached the text file above .pls helpJava Code:package com.lnt.karan; import java.io.*; import java.util.HashMap; import java.util.Scanner; import java.util.Set; public class Copyclass { String newfile = "newfile.txt"; FileReader inputstream = null; public static void main(String[] args) { Copyclass copy = new Copyclass(); copy.copyclass(); } public void copyclass() { File newfile1 = new File(newfile); try { newfile1.createNewFile(); FileInputStream fstream = new FileInputStream("empDetails.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; strLine=br.readLine(); /* HashMap hm = new HashMap(); Set set = hm.entrySet(); */ while ((strLine = br.readLine()) != null) { int c = 0; c= c+1; /* hm.put(strLine, c);*/ System.out.println (strLine); } /* BufferedReader reader = new BufferedReader(FileReader("empDetails.txt")); char c ; c = inputstream.read(); */ } catch(Exception e) { e.printStackTrace(); } } }
regards
karryLast edited by Norm; 01-04-2012 at 02:04 PM. Reason: added code tags
- 01-04-2012, 02:04 PM #2
Re: reading particular line from textfile file
Which lines are the "particular lines"? How can the program determine which lines to print?but don't know how to copy particular lines from the file
Is it the position of the line (say the third line)
or does the line contain a String that you can detect by using some of the String class's methods?
- 01-05-2012, 05:51 AM #3
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
Re: reading particular line from textfile file
yea it is the position of line
- 01-05-2012, 12:22 PM #4
Similar Threads
-
Reading Next Line of File
By smitsky in forum New To JavaReplies: 5Last Post: 12-04-2011, 05:35 PM -
Java- Writing a file and reading a file line by line
By Nazneen Ali in forum New To JavaReplies: 7Last Post: 07-20-2011, 07:56 AM -
Reading a specific line from a file
By efebatistaarda in forum New To JavaReplies: 6Last Post: 02-22-2011, 02:57 PM -
Reading part of a line in a text file
By aaronfsimons in forum New To JavaReplies: 3Last Post: 05-04-2009, 07:57 AM -
Reading in data from file line by line
By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 12:19 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks