[Java lista] jar masolasa

bognár attila attila at netalfa.hu
2007. Feb. 8., Cs, 16:04:23 CET


én a close elé egy flush()-t betennék, az 'inp'-et is illene bezárni.

Maglódszki Viktor írta:
> na most meg igy lejött rendesen:
>  
>  conn = url.openConnection();
>                 inp = conn.getInputStream();
>                
>                 int a;
>                 String theFile = url.getFile();
>                 theFile = theFile.substring(theFile.lastIndexOf('/') + 1);
>                 FileOutputStream fout = new FileOutputStream(theFile);
>                
>                 while ((a=inp.read()) != -1) {
>                     fout.write(a);
>                 }
>                
>                 fout.close();
>  
>  
>
>     ----- Original Message -----
>     *From:* Stef <mailto:stefhun at gmail.com>
>     *To:* javalist at javagrund.hu <mailto:javalist at javagrund.hu>
>     *Sent:* Thursday, February 08, 2007 3:05 PM
>     *Subject:* Re: [Java lista] jar masolasa
>
>     Talan ez segit, mert gondolom szoveges allomanykent jon az a fajl,
>     nem binarisan:
>
>     Save binary file from web
>     <http://www.java2s.com/Code/Java/Network-Protocol/Savebinaryfilefromweb.htm>
>
>     import java.io.FileOutputStream ;
>     import java.io.InputStream;
>     import java.net.MalformedURLException;
>     import java.net.URL;
>     import java.net.URLConnection;
>
>     public class MainClass {
>       public static void main(String args[]) {
>         try {
>           URL root = new URL("http://");
>           saveBinaryFile(root);
>         } catch (MalformedURLException e) {
>           System.err.println("not URL I understand.");
>         }
>       }
>
>       public static void saveBinaryFile(URL u) {
>         int bufferLength = 128;
>         try {
>           URLConnection uc = u.openConnection();
>           String ct = uc.getContentType();
>           int contentLength = uc.getContentLength();
>           if (ct.startsWith("text/") || contentLength == -1) {
>             System.err.println("This is not a binary file.");
>             return;
>           }
>
>           InputStream stream = uc.getInputStream();
>           byte[] buffer = new byte[contentLength];
>           int bytesread = 0;
>           int offset = 0;
>           while (bytesread >= 0) {
>             bytesread = stream.read(buffer, offset, bufferLength);
>             if (bytesread == -1)
>               break;
>             offset += bytesread;
>           }
>           if (offset != contentLength) {
>             System.err.println("Error: Only read " + offset + " bytes");
>             System.err.println("Expected " + contentLength + " bytes");
>           }
>
>           String theFile = u.getFile();
>           theFile = theFile.substring(theFile.lastIndexOf('/') + 1);
>           FileOutputStream fout = new FileOutputStream(theFile);
>           fout.write(buffer);
>         } catch (Exception e) {
>           System.err.println(e);
>         }
>         return;
>       }
>     }
>
>     Stef
>
>
>     2007/2/8, Maglódszki Viktor < bocios at citromail.hu
>     <mailto:bocios at citromail.hu>>:
>
>         Sziasztok !
>          
>         Szeretnék egy távoli gépről http-n lemásolni egy JAR fájlt.
>         Sajnos webem még nincs, de itt van nálam a kék java könyv.
>         2 féle képpen próbáltam.
>          
>         URL url = new URL(http://IPCIM/progi.jar);
>         URLConnection conn = url.openConnection();
>         InputStream inp = conn.getInputStream();
>          
>         azután 1 BufferedReader segitségévél végimentem az
>         inputstream-en és ezt betettem egy létrehozott üres jar fájlba.
>         Szépen átment, de a jar-t nem tudom elinditani.
>         java -jar progi.jar kimenete:
>         invalid or corrupt jar file
>          
>         egy sima TXT-vel kipróbálva pedig működik
>          
>         A könyv még emlitit a JarURLConnection -t is.
>         Azokra mond példát, hogy egy benne lévő class-t hogyan tudok
>         elérni, de én le szeretném másolni.
>         Ha simán hivatkozom a jar-ra nem megy:
>          
>         URL url = new URL(http://IPCIM/progi.jar);
>         JarURLConnection jC = (JarURLConnection)url.openConnection();
>         inp = jC.getInputStream();
>          
>         ez sajnos IOException-t okoz:
>          
>         java.io.IOException: no entry name specified
>                 at
>         sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:129)
>          
>         lehet ezzel a JarURLConnection objektumal vagy mással az egész
>         JAR fájlt átmásolni?
>          
>         előre is köszönöm !
>          
>         üdv, MV
>
>         _______________________________________________
>         Javalist mailing list
>         Javalist at javagrund.hu <mailto:Javalist at javagrund.hu>
>         http://javagrund.hu/mailman/listinfo/javalist
>
>
>     ------------------------------------------------------------------------
>     _______________________________________________
>     Javalist mailing list
>     Javalist at javagrund.hu
>     http://javagrund.hu/mailman/listinfo/javalist
>
>     ------------------------------------------------------------------------
>     No virus found in this incoming message.
>     Checked by AVG Free Edition.
>     Version: 7.5.432 / Virus Database: 268.17.25/669 - Release Date:
>     2007.02.04. 21:58
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Javalist mailing list
> Javalist at javagrund.hu
> http://javagrund.hu/mailman/listinfo/javalist
>   
--------- következő rész ---------
Egy csatolt HTML állomány át lett konvertálva...
URL: http://javagrund.hu/pipermail/javalist/attachments/20070208/b3d2f0d6/attachment-0001.html 


További információk a(z) Javalist levelezőlistáról