How do i calculate and read file in java--- I JUS NEED LITTLE HINTS TO CALCULATE THE LINE AND READ IT?
-
I WROTE THIS SO FAR AND ITS WORKING AND OPENING ANY FILE BUT I WANT TO CALCULATE AND READ MY FILES LINE BY LINE... CAN I GET SOME HELP HOW DO I DO THIS import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.LineNumberReader; import java.util.Scanner; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class heptathlon { public static void main(String[] args) throws Exception { JFileChooser fc = new JFileChooser(); if (fc.showOpenDialog(null)== JFileChooser.APPROVE_OPTION) { java.io.File file = fc.getSelectedFile(); Scanner input = new Scanner(file); while (input.hasNext()) { System.out.println( input.nextLine()); } input.close(); } else { System.out.println("NO FILE SELECTED"); } } }
-
Answer:
Allocate a String object before the loop, like this: String sTmp = ""; In the loop where you have: System.out.println( input.nextLine()); Change it to these two lines: sTmp = input.nextLine(); read the next line into 'sTmp' System.out.println( sTmp );
Chris C at Yahoo! Answers Visit the source
Related Q & A:
- How do I calculate a xyz-position of a GPS-position relative to an other GPS-position?Best solution by Geographic Information Systems
- How can I make a Spinner only by java?Best solution by stackoverflow.com
- How do I do a HTTP GET in Java (android?Best solution by Stack Overflow
- how can I listen for database changes using java?Best solution by Stack Overflow
- Which schools should I apply to in the US and how do I calculate my GPA?Best solution by csumentor.edu
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.