Code example for RandomAccessFile

Methods: close, length, read

0
	public static long getCRC32(String filename)
	{ 
		// Attempt to read the file from disk 
		try 
		{ 
			RandomAccessFile file = new RandomAccessFile(filename, "r");
			 
			// Convert the file to a buffer 
			byte[] buffer = new byte[(int)file.length()];
			file.read(buffer);
			 
			// Generate the CRC from the buffer 
			CRC32 crc = new CRC32();
			crc.update(buffer);
			file.close();
			// Return the generated CRC 
			return crc.getValue();
		} 
		catch(IOException e)
		{ 
			// If the file doesn't exist, return 0 as CRC