Results 1 to 2 of 2
Thread: read file
- 05-09-2010, 03:51 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 61
- Rep Power
- 0
read file
hey every body
this code is the action of JButton , this read the first 10 linesJava Code:public void readSura() { sNumber = jComboBox1.getSelectedIndex(); jTextArea1.setText(null); System.out.print(sNumber); file = new File("qu/" + sNumber); try { input = new Scanner(file); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, "can't fine file", "error", JOptionPane.ERROR_MESSAGE); } while (input.hasNextLine() && noOfLines < 10) { //read first 10 lines fro file String outPut = input.nextLine(); jTextArea1.append(outPut+"\n\n"); ++ noOfLines; } input.close(); }
i want if a press on it again read the next 10 lines .... etc , plz i need help??
-
You'll have to declare your Scanner object outside of the readSura method so that it has a state that persists after the method has concluded.
Similar Threads
-
Read a file and converting this file into a string
By kostinio in forum New To JavaReplies: 7Last Post: 12-26-2009, 03:54 PM -
Read file from directory, update contents of the each file
By svpriyan in forum New To JavaReplies: 2Last Post: 05-11-2009, 10:07 AM -
how to read openproj(Projity) file i.e. ,POD file(Project Management file)
By mahendra.athneria in forum New To JavaReplies: 0Last Post: 02-11-2009, 09:53 AM -
How to read and write to a file without taking out the comments in the file
By MAGNUM in forum New To JavaReplies: 5Last Post: 02-05-2009, 10:28 AM -
How to read a text file from a Java Archive File
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks