Код (Text): for ( int i=1024; i>=1; i--){ int d8 = fileSize%i; int d9 = fileSize/i; if (d8 == 0) { int hq = fileSize/d9; //bytes lost cols = hq; this.hBytes = d9; //bytes available }
Вот тебе весь код (урезан) Код (Text): class RemoteFileReader extends Thread{ protected String fileName; protected int hBytes; protected int fileSize; RemoteFileReader (String fileName){ // - init class this.fileName = fileName; } protected int splitSource(){ int cols = 0; URL u = new URL (this.fileName); URLConnection c = u.openConnection(); int fileSize = c.getContentLength(); this.fileSize = fileSize; for ( int i=1024; i>=1; i--){ int d8 = fileSize%i; int d9 = fileSize/i; if (d8 == 0) { int hq = fileSize/d9; cols = hq; this.hBytes = d9; break; } } return cols; } public void DownloadFileA(int offset, int limit){ URL u = new URL (this.fileName); URLConnection c = u.openConnection(); InputStream is = c.getInputStream(); byte[] b = new byte[this.fileSize]; is.read(b,offset,limit); File f = new File("r.rar"); System.out.println("Downloading "+u.getFile()); FileOutputStream fo = new FileOutputStream(f); fo.write(b); } public void run(){ splitSource(); DownloadFileA(0,this.fileSize); } } ... RemoteFileReader rfr = new RemoteFileReader("http://www.slil.ru/23434535/1340418263/archive.rar"); rfr.start();