Code example for RandomAccessFile

Methods: closegetChannellength

0
	 */ 
	public static void main(String[] args) throws IOException {
		RandomAccessFile raf = null;
		FileOutputStream fos = null;
		try { 
			raf = new RandomAccessFile("f:/googleDownloads/mysql-5.5.31-win32.zip", "rw");
			FileChannel inChannel = raf.getChannel();
			 
			MappedByteBuffer mBuffer = inChannel.map(FileChannel.MapMode.READ_WRITE, 0, raf.length());
			 
			fos = new FileOutputStream("f:/mysql-5.5.31-win32.zip");
			FileChannel outChannel = fos.getChannel();
			 
			outChannel.write(mBuffer);
			 
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{ 
			if(raf != null)
				raf.close();
			if(fos != null)
				fos.close();
		} 
 
	} 
Experience pair programming with AI  Get Codota for Java