View Single Post
  #2 (permalink)  
Old 07-25-2007, 05:44 PM
shanePreater shanePreater is offline
Member
 
Join Date: Jul 2007
Location: England, Bath
Posts: 47
shanePreater is on a distinguished road
Your problem is that you are creating an extra BufferedReader if you remove the creation of userInput and re-use the inputFile variable the bufferedReader should work better.

Also you want to add a finally block to ensure the readers are all closed at the end.

Here is one I have edited for you:

Code:
BufferedReader userInput = null; BufferedReader input = null; PrintWriter outputFile = null; try { System.out.print("Enter the input filename: ");// open file userInput = new BufferedReader(new InputStreamReader(System.in)); String str = userInput.readLine(); input = new BufferedReader(new FileReader(str)); System.out.print("Enter the output filename: "); String str1 = userInput.readLine(); outputFile = new PrintWriter(new FileOutputStream(str1));// create // output // file int numberOfSeries = Integer.parseInt(input.readLine()); for (int i = 0; i < numberOfSeries; i = i + 1) { int maximum = 0, minimum = 99999; int numberOfValues = Integer.parseInt(input.readLine()); int[] dataSpread = new int[numberOfValues]; for (int t = 0; numberOfValues > t; numberOfValues = numberOfValues - 1) { int dataValue = Integer.parseInt(userInput.readLine()); if (dataValue > maximum) dataValue = maximum; if (dataValue < minimum) dataValue = minimum; dataValue = dataSpread[numberOfValues - 1]; } } } catch (IOException e) { System.out.println("Error occured, please restart application."); } finally { try { // close all the readers. input.close(); userInput.close(); outputFile.flush(); outputFile.close(); } catch (Exception e) { e.printStackTrace(); } }
Hope this helps.
__________________
Shane Preater -
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote