Below is my code that will read lines from URL and output it.
I was wondering how can I also output line numbers such as row numbers in excel.
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Scanner;
public class helloworld {
public static void main(String[] args) throws IOException {
URL yahh = new URL("https://docs.google.com/spreadsheet/pub?key=0AqSBI1OogE84dDJyN0tyNHJENkNyYUgyczVLX0RMY3c&single=true&gid=0&range=A2%3AA200&output=txt");
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahh.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
Currently Output is:
11111
22222
33333
44444
55555
66666
77777
88888
99999
100000
I want it to be
1 11111
2 22222
3 33333
4 44444
5 55555
6 66666
7 77777
8 88888
9 99999
10 100000
declare a
line numbervariable andincrementit inside your loop on every iteration: