• [Java] Biblioteca de Arquivos

  • Download de arquivos por HTTP

  • 			public static void downloadHTTP(String from, String to) throws IOException {
    				java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(from).openStream());
    				java.io.FileOutputStream fos = new java.io.FileOutputStream(to);
    				java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
    				byte[] data = new byte[1024];
    				int x = 0;
    				while ((x = in.read(data, 0, 1024)) >= 0) {
    					bout.write(data, 0, x);
    				}
    				bout.close();
    				in.close();
    			}
  • Copiar pastas, subpastas e arquivos

  • 			public static void copyFolder(String strSrc, String strDest) throws IOException {
    				File src = new File(strSrc);
    				File dest = new File(strDest);
    			
    				if (src.isDirectory()) {
    					if (!dest.exists())
    						dest.mkdir();
    			
    					String files[] = src.list();
    					for (String file : files) {
    						File srcFile = new File(src, file);
    						File destFile = new File(dest, file);
    						copyFolder(srcFile.getAbsolutePath(), destFile.getAbsolutePath());
    					}
    			
    				} else
    						copyInputStream(new FileInputStream(src), new FileOutputStream(dest));
    			}
    • Tecnologia:
    • Testado:
  • Desde 2010 | Designer e Desenvolvimento por Johny W. Alves