im trying limit size creation of 1 file in java app. made sample code declare 1 variable lenght of 32 bytes, start writeonfile method looping until 32 bytes. problem is, doesnt matter value set set on file_size (higher or lower) download file coming 400kb - means code working since original file 200mb has logic mistake. there way this? cos based myself on post how limit file size in java , until found nothing better
i wondering if has bufferedwriter...
thanks in advance help
public static final byte file_size = 32; private static void writeonfile(bufferedwriter writer, string crawlingnode){ try { while(file.length()<file_size){ writer.write(crawlingnode); system.out.println(file.length()); } } catch (ioexception e) { joptionpane.showmessagedialog(null, "failed write url node"); e.printstacktrace(); } }
i tried around little bit , write files 32 bytes large limiting bufferedwriter's write-method directly:
writer.write(crawlingnode, 0, 32); with call, first 32 chars written file. encoding utf-8, means every char occupies 1 byte, size of output file 32 bytes. writing 16 chars resulted in file of 16 bytes , forth.
so maybe use without implementing other big stuff.
edit:
if string has less characters 32, use following call:
writer.write(crawlingnode, 0, crawlingnode.length);
Comments
Post a Comment