Esse c�digo at� funciona, mas � muito lento pois vai ler byte a byte...
Tente esse:
//Copies one file into another.
public void copyFile (File source, File destiny) {
FileInputStream in;
FileOutputStream out;
int amount;
byte[] bytes = new byte[1024];
try {
in = new FileInputStream(source);
out = new FileOutputStream(destiny);
amount = in.read(bytes);
while (amount == 1024) {
out.write(bytes);
amount = in.read(bytes);
}
if (amount != -1) out.write(bytes, 0, amount);
in.close();
out.close();
}catch (FileNotFoundException fnfe) {
}catch (IOException ioe) {
}
}
Rogerio Augusto Costa wrote:
> Olha este codigo!!! (copie!!)
>
> import java.io.*;
>
> public class CopyFile {
>
> public static void main(String args[]) {
>
> // Verifica os dois argumentos
> if (args.length != 2) {
> System.out.println("Erro na passagem de argumento");
> System.exit(-1);
> }
>
> // Pega o argumento de entrada
> String infile = args[0];
>
> // Pega o argumento de saida
> String outfile = args[1];
>
> // Cria variaveis de entrada e saida
> FileInputStream fis = null;
> FileOutputStream fos = null;
>
> try {
> // Cria o stream de entrada
> fis = new FileInputStream(infile);
>
> // Cria o stream de saida
> fos = new FileOutputStream(outfile);
>
>
> int ch;
>
> // L� os bytes ate o fim do arquivo
> while ((ch = fis.read()) != -1) {
>
>
> // Coloco os bytes no stream
> fos.write(ch);
> }
>
> } catch (FileNotFoundException e) {
> System.err.println("Arquivo nao encontrado: " + e);
>
> } catch (IOException e) {
> System.err.println("Erro de I/O : " + e);
>
> // Fecha os Arquivos
> } finally {
> if (fis != null) {
> try {
> fis.close();
> } catch (IOException ignored) {
> }
> }
> if (fos != null) {
> try {
> fos.close();
> } catch (IOException ignored) {
> }
> }
> }
> }
> }
>
> Glauco Cesar de Castro wrote:
>
> >Ola para todos.
> >
> >Como faco para copiar um arquivo?
> >Ex:
> >
> >Copiar c:\teste.txt para d:\teste.txt
> >
> >Obrigado,
> >Glauco
> >
> >
> >------------------------------ LISTA SOUJAVA ----------------------------
> >http://www.soujava.org.br - Sociedade de Usu�rios Java da Sucesu-SP
> >d�vidas mais comuns: http://www.soujava.org.br/faq.htm
> >regras da lista: http://www.soujava.org.br/regras.htm
> >historico: http://www.mail-archive.com/java-list%40soujava.org.br
> >para sair da lista: envie email para [EMAIL PROTECTED]
> >-------------------------------------------------------------------------
> >
> >
> >
> >
> >
> >
>
> ------------------------------ LISTA SOUJAVA ----------------------------
> http://www.soujava.org.br - Sociedade de Usu�rios Java da Sucesu-SP
> d�vidas mais comuns: http://www.soujava.org.br/faq.htm
> regras da lista: http://www.soujava.org.br/regras.htm
> historico: http://www.mail-archive.com/java-list%40soujava.org.br
> para sair da lista: envie email para [EMAIL PROTECTED]
> -------------------------------------------------------------------------
------------------------------ LISTA SOUJAVA ----------------------------
http://www.soujava.org.br - Sociedade de Usu�rios Java da Sucesu-SP
d�vidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
historico: http://www.mail-archive.com/java-list%40soujava.org.br
para sair da lista: envie email para [EMAIL PROTECTED]
-------------------------------------------------------------------------