Descargar un archivo de internet
Posted on September 22nd, 2007 in Código, Java |
Estas lineas de código nos permite descargar un archivo desde la red y guardarlo en algún medio de almacenamiento local.
JAVA:
-
import java.io.BufferedInputStream;
-
import java.io.FileOutputStream;
-
import java.io.IOException;
-
import java.net.MalformedURLException;
-
import java.net.URL;
-
-
public class GetFileExample
-
{
-
public GetFileExample()
-
{
-
try
-
{
-
byte[] bite = new byte[2048];
-
int read;
-
-
-
while((read = bis.read(bite))>0)
-
{
-
fos.write(bite, 0, read);
-
}
-
-
fos.close();
-
bis.close();
-
-
-
}
-
{
-
e.printStackTrace();
-
}
-
{
-
e.printStackTrace();
-
}
-
}
-
-
{
-
new GetFileExample();
-
}
-
}
Popularidad: 39%

