Showing posts with label jdk7. Show all posts
Showing posts with label jdk7. Show all posts

Thursday, 28 July 2011

Read a Text File Using JDK7

Duke WavingHere is a really simple example of how to read a text file using JDK7. The main new feature you will see is the try with resources block on line 10. The program just numbers the lines of a text files up to 9999 lines long.



LineNumber.java

   1 import java.io.BufferedReader;
2 import java.io.FileNotFoundException;
3 import java.io.FileReader;
4 import java.io.IOException;
5
6 public class LineNumber {
7 public static void main(String[] args){
8 String fileName = args[0];
9
10 try(BufferedReader reader = new BufferedReader(new FileReader(fileName))){
11 String line = ""; int c = 1;
12 while((line = reader.readLine()) != null){
13 System.out.printf("%4d %s\n", c, line);
14 c++;
15 }
16
17 } catch (FileNotFoundException e) {
18 e.printStackTrace();
19 } catch (IOException e){
20 e.printStackTrace();
21 }
22 }
23 }


Text Version of the Source Code

Thursday, 7 July 2011

JDK 7 Launch Going on Right Now

Duke WavingWant to see the JDK 7 launch event? It is going on live right now. More information can be found here. I am not sure if there are still login slots available, but you can always check it out if interested.

Tuesday, 28 June 2011

JavaDoc can now be styled

Duke Waving

Yes folks, you can now style your javadoc with CSS. Check out the details here:

New Javadoc for Java SE 7