elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Tutorial básico de Quickjs


  Mostrar Mensajes
Páginas: 1 ... 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 [56] 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 ... 79
551  Programación / Java / Re: [SOURCE]Mini-BotNet en java (Falta arreglar una cosa) en: 7 Enero 2010, 15:04 pm
Bueno es que ago mejores interfazes en eclipse sin mucho trabajo  por eso no lo uso :P

Saludos.
552  Programación / Java / Re: Cliente-servidor en: 7 Enero 2010, 15:01 pm
Rectifico, ya lo he consegui, aqui el metodo:

Código
  1. int porcentaje = 0;
  2.                        System.out.println(porcentaje);
  3. while((read = stream.read(data)) > 0){
  4.  
  5.  
  6. offset += read;
  7.                                porcentaje = (offset * 100)/SIZE;
  8.                                System.out.println(porcentaje);
  9.  
  10. fileOutputStream.write(data,0,read);
  11.   }
  12.  

cierto esta listo para un progressBar aunke fuera bueno que en la salida se imprimiera en una sola linea y no salte a la siguiente desconozco eso.

LEYER gracias por tu aporte uan vez mas, el ejemplo que me pones me gusta mas ya que lleva threads incorporados.  El codigo esta muy claro tambien.
Cualquier cosa os comento.
Salu2.
alzehimer_cerebral
:)
553  Programación / Java / Re: Cliente-servidor en: 6 Enero 2010, 19:32 pm
 ;) bien!

esta es la segunda forma

Código
  1. import java.io.File;
  2. import java.io.FileOutputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8.  
  9. /**
  10.  * @author Leyer
  11.  */
  12. public class ThreadForDownload extends Thread{
  13. public static void main(String []args){
  14. try {
  15. new ThreadForDownload(new URL("http://www.tecnun.es/asignaturas/Informat1/ayudainf/aprendainf/Java/Java2.pdf"),"/home/leyer").start();
  16. } catch (MalformedURLException e) {
  17. // TODO Auto-generated catch block
  18. e.printStackTrace();
  19. }
  20. }
  21. private URL           url          =   null;
  22. private URLConnection connection   =   null;
  23. private int offset = 0;
  24. private boolean init   = true;
  25. String path;
  26. private FileOutputStream fileOutputStream;
  27. public ThreadForDownload(
  28. final URL URL,
  29. String path) {
  30. this.url = URL;this.path = path;
  31. }
  32.  
  33. @Override
  34. public synchronized void run() {
  35. while(init){
  36. try {
  37. System.out.println("-----------------------------------");
  38. System.out.println("Host: "+url.getHost());
  39. System.out.println("NOmbre del Archivo: "+getFileName(url));
  40. System.out.println("Tamaño: "+getLength(url));
  41. System.out.println("-----------------------------------");
  42. connection = url.openConnection();
  43. } catch (IOException e) {System.err.println("Error in conection!");System.exit(0);
  44. } catch (Exception e) {
  45. e.printStackTrace();System.exit(0);
  46. }
  47. int read = 0;
  48. final int SIZE = getLength(url);
  49. InputStream stream  =  null;
  50. try {
  51. System.out.println("wait...");
  52.    stream = connection.getInputStream();
  53. fileOutputStream = new FileOutputStream(path+""+File.separator+getFileName(url));
  54. final byte[] data = new byte[SIZE];
  55. while((read = stream.read(data)) > 0){
  56. offset +=read;
  57. fileOutputStream.write(data,
  58. 0,
  59. read);
  60.   }
  61. try{
  62. System.out.println("Completado!");
  63. fileOutputStream.flush();
  64. fileOutputStream.close();
  65. offset = 0;  init = false;
  66. break;
  67.    }catch (Exception e) { }
  68. }catch (Exception e1) {
  69.  }
  70.   }
  71. }
  72.  
  73. public void setInit(boolean init) {
  74. this.init =false;
  75. }
  76. final int getLength(URL urlFile){
  77. URLConnection connection = null;
  78. int size = 0;
  79. try {
  80. connection = urlFile.openConnection();
  81. size = connection.getContentLength();
  82. } catch (IOException e) {
  83. System.err.println(e+":ERROR");System.exit(0);
  84. } catch (Exception e) {
  85. System.err.println(e+":ERROR");System.exit(0);
  86. }
  87. return size;
  88. }
  89. private final String getFileName(URL URL){
  90.     String path=URL.getPath();
  91.     int lastIndexOf=path.lastIndexOf("/");
  92.     String name = path.substring(lastIndexOf+1);
  93. return name;
  94.  
  95. }
  96. }

PD: lo hice al instante asi que errores en el codigo se aceptan
554  Programación / Java / Re: Cliente-servidor en: 6 Enero 2010, 19:19 pm
Me parece que alguien debe leerse un buen tutorial de Sockets, en el paquete .net está todo lo que necesitas, toma el InputStream del socket, empieza a leer los datos que te envia el server y ya lo tienes.
:P pero si el lo esta haciendo asi ps que lo siga haciendo no es mucha la diferencia
555  Programación / Java / Re: Cliente-servidor en: 6 Enero 2010, 19:11 pm
esta es la lib http://www.java2s.com/Code/JarDownload/commons-httpclient.jar.zip

Saludos!
556  Programación / Java / Re: Cliente-servidor en: 6 Enero 2010, 18:44 pm
bueno solo  te quedaria solo descargarlo del servidor como cuarquier archivo :P

Salu2
557  Programación / Java / Re: Cliente-servidor en: 6 Enero 2010, 17:27 pm
osea pero el servidor lo tienes que creear tu, un servidor apache no es necesario a no ser que te conectes http://localhost:8081/ en tu apache

Saludos!
558  Programación / Java / Re: Explicacion de un simple ejercicio en: 6 Enero 2010, 06:07 am
 1-
Citar
pero porque entre parentesis la siguiente linea: (posicion + 1 < arreglo.length ? ";" : "") y para que sirve el signo ? y las comillas y los ; y :

se le llama operador ternario en esa linea te dice que si la posicion+1 < arreglo.length si es verdadero entonces a la cadena se le coloca un ";" en caso contrario se le coloca un ":"

2-
Citar
Luego tampoco entiendo para que sirve:  strAños = años.split(";");

quiere decir que si tienes

Código
  1. String años = "1990;1991";
  2. String strAños[]= años.spli(";");
  3.  
optendrias un array con los valores 1990 1991.

Saludos!

559  Programación / Java / Re: [SOURCE]Mini-BotNet en java (Falta arreglar una cosa) en: 5 Enero 2010, 23:57 pm
genial aunke la gui esta muy simple para estar hecha en netbans :-\ tambien podrias aplicarle el Look and fell del sisema

Código
  1. try{
  2.     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch (Exception e) {
  3. };
560  Programación / Java / Re: Como ver el codigo fuente de una web con Java? en: 5 Enero 2010, 23:55 pm
simple

Código
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.InputStreamReader;
  5. /**
  6.  * @author Leyer
  7.  */
  8. public class Test {
  9. public static void main(String []args){
  10. try {
  11. new Test();
  12. } catch (IOException e) {
  13. e.printStackTrace();
  14. }
  15. }
  16. public Test() throws IOException{
  17. try {
  18. java.net.URL url = new java.net.URL("http://www.google.co.ve/");
  19. java.net.URLConnection con = url.openConnection();
  20. InputStream s = con.getInputStream();
  21. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(s));
  22. String line = "";
  23. while((line = bufferedReader.readLine())!=null){
  24. System.out.println(line);
  25. }
  26. } catch (java.net.MalformedURLException e) {
  27. // TODO Auto-generated catch block
  28. e.printStackTrace();
  29. }
  30. }
  31. }

Saludos!
Páginas: 1 ... 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 [56] 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 ... 79
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines