Upload de Arquivo Usando Stream [RESOVIDO]

2 respostas
Z

Galera só uma ajudinha simples primeiro vou postar o código que vocês entenderão facilmente.

public class Teste {

		public static void main(String[] args) throws IOException {
		File file = new File ("C:\repetidos.txt");
		File file2 = new File (file, "repetidos");
		FileReader reader = new FileReader(file);
		BufferedReader leitor = new BufferedReader(reader);
		FileWriter writer = new FileWriter("C:\teste");
		PrintWriter saida = new PrintWriter(writer);
		saida.println("testeT");
		String linha;
		do {
		linha = leitor.readLine();
		if (linha != null)
		System.out.println(linha);
		} while (linha != null);
		leitor.close();
		reader.close();
		saida.close();
		writer.close();
		}
		
		}

Galera com esse código eu consigo ler um arquivo (repetidos.txt) e criar um novo arquivo chamado teste e inserindo a String testeT nele, o que eu gostaria de saber, é como eu posso pegar o arquivo(repetidos.txt) e enviar para uma pasta criada no diretorio C: ---- valeww

2 Respostas

R

From our friend Google:

// Copies src file to dst file.
    // If the dst file does not exist, it is created
    void copy(File src, File dst) throws IOException {
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dst);
    
        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    }

[]´s

Z

Ae deu certo valew Rafael pela sua ajuda. Vou postar o código caso alguém tenha a mesma duvida.

public class Arquivos {

		public static void main(String[] args) throws IOException {
		File file = new File ("C:\Logo.jpg");
		File file2 = new File ("C:\teste\imagem.jpg");
		file2.createNewFile();
		//FileReader reader = new FileReader(file);
		//BufferedReader leitor = new BufferedReader(reader);
		FileInputStream in = new FileInputStream(file);
		FileOutputStream out = new FileOutputStream(file2);
		byte[] buf = new byte[1024];   
	    int len;   
	    while ((len = in.read(buf)) > 0) {   
	        out.write(buf, 0, len);   
	    }   
		in.close();
		out.close();
		}
		}
Criado 20 de fevereiro de 2008
Ultima resposta 20 de fev. de 2008
Respostas 2
Participantes 2