Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/05/2014, 09:32
trinbarranca
 
Fecha de Ingreso: abril-2014
Mensajes: 6
Antigüedad: 10 años, 1 mes
Puntos: 0
convertir array de bytes y dividir...

una vez el archivo convertido a array de bytes, ¿se puede transferir por una red y al llegar al cliente este convierta el array de bytes a archivo?, si es que fuera asi, ¿se puede convertir un archivo a array de bytes y despues dividir esos bytes en dos grupos para ser guardados en diferentes computadores?


buscando por internetí, lo que mas se parece a lo que busco es esto:



import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class genFile {

public static void main(String[] args) throws FileNotFoundException, IOException {
File file = new File("java.pdf");

FileInputStream fis = new FileInputStream(file);
//System.out.println(file.exists() + "!!");
//InputStream in = resource.openStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
//Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
System.out.println("read " + readNum + " bytes,");
}
} catch (IOException ex) {
Logger.getLogger(genJpeg.class.getName()).log(Leve l.SEVERE, null, ex);
}
byte[] bytes = bos.toByteArray();

//below is the different part
File someFile = new File("java2.pdf");
FileOutputStream fos = new FileOutputStream(someFile);
fos.write(bytes);
fos.flush();
fos.close();
}
}

¿pero como hago para dividir un solo archivo de cualquier tipo, "no uno especifico como texto, sino cualquiera", en dos array de bytes?