Results 1 to 2 of 2
  1. #1
    ndsmith20 is offline Member
    Join Date
    Oct 2012
    Posts
    55
    Rep Power
    0

    Default Need help reading a .dat file and printing out with printf

    Hi, I have a .dat file that i need to read and then compute average grades, print the average and then format with printf. I can read the file and get it to print but it comes out looking exactly the same as the .dat file instead of formatting to something the human mind can read, this is what I have:
    (I have included the the whole program including .dat file as an attachment)
    :
    Java Code:
    * Date: 3/13/13
    * Class: ByteLab1
    */
    
    import java.io.*;
    
    public class ByteLab1{
    	public static void main(String args[]) { 
     		try { 
    			FileInputStream fis = new FileInputStream("ClassList.dat"); 
    			BufferedReader in = new BufferedReader(new InputStreamReader(fis));
     			while(true){ 
    				String line = in.readLine();
    				if(line == null) break;
    				System.out.println(line);
    				//fis.close();
    			}
    			/*
    			int length = in.readInt();
    			System.out.println(""+length);
    			StringBuilder out = new StringBuilder();
    			for(int i = 0; i < length; i++){
    				out.append(in.readChar());
    				System.out.println(out.toString());
    			*/
    			 
     		} 
    		catch(IOException ioe) { 
    			System.out.println("Exception:"+ioe.getMessage());
    		}
    	}
    }
    Attached Files Attached Files

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Need help reading a .dat file and printing out with printf

    You're not using printf, that's why it looks the same as in the file.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Reading .txt contents and printing them to java GUI
    By hinkey1 in forum AWT / Swing
    Replies: 1
    Last Post: 09-30-2012, 06:41 AM
  2. printf VS printWriter.printf
    By Mapisto in forum New To Java
    Replies: 14
    Last Post: 01-20-2012, 12:29 PM
  3. Replies: 6
    Last Post: 01-19-2012, 05:16 PM
  4. reading lines from URL and printing backwards
    By luxurymode in forum Advanced Java
    Replies: 1
    Last Post: 03-30-2011, 08:18 AM
  5. adding printf to system.in file
    By bettyhagan in forum New To Java
    Replies: 2
    Last Post: 12-21-2009, 11:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •