package inchestable; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class InchesTable { public static void printTable(BufferedWriter bw) throws IOException { bw.write("Inches CM"); bw.newLine(); for(int inches=1; inches<20; inches++) { bw.write(String.format("%2d %.2f%n",inches, inches*2.54)); }//for }//printTable public static int openFile()throws IOException { try { File helloFile = new File("c:/myData/inches.txt"); if (!helloFile.exists()) { helloFile.createNewFile(); } //doesn't exist create it, otherwise overwrite it FileWriter fw = new FileWriter(helloFile.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); printTable(bw); bw.close(); return 1;//success } //try catch (IOException e) { return 0; //failure } //catch }//openFile public static void main(String[] args) throws IOException { int result=openFile(); if(result==0)System.out.println("File could not be created"); else System.out.println("File created successfully"); }//main }//class