Demo entry 6722493

javaweb project test

   

Submitted by anonymous on Mar 23, 2018 at 03:56
Language: Java. Code size: 508 Bytes.

public byte[] getFileBytes(File filename){
		byte[]buffer = null;
		try {
			FileInputStream fis = new FileInputStream(filename);
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			byte[]b = new byte[1000];
			int n;
			while((n=fis.read(b)) != -1){
				bos.write(b,0,n);
			}
			fis.close();
			bos.close();
			buffer = bos.toByteArray();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return buffer;
	}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).