View Single Post
Old 29-09-2004, 13:25   #2
philip.j.fry
Inactive
 
philip.j.fry's Avatar
 
Join Date: Jul 2003
Posts: 1,395
philip.j.fry has reached the bronze age
philip.j.fry has reached the bronze agephilip.j.fry has reached the bronze agephilip.j.fry has reached the bronze agephilip.j.fry has reached the bronze age
Re: Calling al Programmers plese

Here's something written in Java, it shows the Hex an Dec values. To run just provide the name of the file you want to scan as the first command line agument, e.g.

java check_sumthing <filename>

Note that things like spaces and new line characters count towards the total.


Code:
import java.io.*;


public class check_sumthing
{
	
	private static FileReader infile = null;
	private static BufferedReader instream = null;
	private static int finalint = 0;

	public static void main(String[] args)
	{
		
		if(args.length == 0)
		{
			System.out.println("No filename provided\nUsage: \"java check_sumthing <filename>\"");
		}
		
		try
		{
			infile = new FileReader(args[0]);
			instream = new BufferedReader(infile);
			
			int in;
			while ((in = instream.read()) != -1)
			{
				finalint += in;
			}
			instream.close();
		}
		catch(IOException e)
		{
			System.out.println("There was an error reading from the file, did you give the correct filename?");
		}
		
		System.out.println("Dec: " + finalint);
		System.out.println("Hex: " + Integer.toHexString(0x10000 | finalint).substring(1).toUpperCase());	
		
	}//end main(...)

}
philip.j.fry is offline   Reply With Quote