java - Reading in sets of 64 characters from a file -
so i'm trying read in string file. however, want each string contain 64 characters or less if last string doesn't have 64 in it. have counter, when counter reaches 64, set array of characters string, go next row , reset count zero. i'm not getting output of kind when run it. appreciated. here snippet of code
public static void main(string[] args) throws ioexception{ file input = null; if (1 < args.length) { input = new file(args[1]); } else { system.err.println("invalid arguments count:" + args.length); system.exit(0); } string key = args[0]; bufferedreader reader = null; int len; scanner scan = new scanner(system.in); system.out.println("how many lines in file?"); if(scan.hasnextint()){ len = scan.nextint(); } else{ system.out.println("please enter integer: "); scan.next(); len = scan.nextint(); } scan.close(); string[] inputtext = new string[2 * len]; string[] encrypttext = new string[2 * len]; char[][] inputchararr = new char[2 * len][64]; reader = new bufferedreader(new filereader(input)); int r; int counter = 0; int row = 0; while ((r = reader.read()) != -1) { char ch = (char) r; if(counter == 64){ string temp = new string(inputchararr[row]); inputtext[row] = temp; encrypttext[row] = inputtext[row]; system.out.println(inputtext[row]); row++; counter = 0; } if(row == len){ break; } inputchararr[row][counter] = ch; counter++; }
edit: close?
charbuffer cbuf = charbuffer.allocate(64); int counter = 0; while (reader.read(cbuf) != -1) { inputtext[counter] = cbuf.tostring(); encrypttext[counter] = inputtext[counter]; counter++; cbuf.clear(); }
Comments
Post a Comment