On Thursday 13 of October 2005 10:16, Tomas Bauer wrote:
> Ahoj, zkus to přes resourcy, něco jako:
>
> MyClass.class.getResource(DIR_IMG + aPath);
>
Jenom dodam, ze obsah adresare res se typicky mapuje do rootu vysledneho jaru, 
takze mpg z ..../res/muj.mpg si normalne otevres pres
this.getClass().getResourceAsStream("/muj.mpg");

Pro ukazku prikladam metodu, kterou si soubory nacitam ja:
{
...
byte[] mpg = loadFile("/muj.mpg);
...
}

    public byte[] loadFile(String file) {

        // load up the resource strings
        InputStream is = null;
        byte[] result = null;
        try {
            is = this.getClass().getResourceAsStream(file);
            if (is == null) {
                return null;
            }
            byte[] buffer = new byte[1024];
            Vector vector = new Vector();
            int bytesRead = 0;
            // read a line and add the entries
            do {
                bytesRead = is.read(buffer);
                if (bytesRead != -1) {
                    vector.addElement(buffer);
                    buffer = new byte[1024];
                }
            } while (bytesRead == 1024);
            if (vector.size() != 0) {
                if (bytesRead == -1) {//i*1024
                    bytesRead = 1024;//fall back to the maximum length
                }
                result = new byte[1024 * (vector.size()-1)+bytesRead];
                int i = 0;
                while (i<vector.size()-1) {
                    
System.arraycopy(vector.elementAt(i),0,result,i*1024,1024);
                    i++;
                }
                
System.arraycopy(vector.elementAt(i),0,result,i*1024,bytesRead);
            }
        } catch(IOException io) {
            if (ERROR) System.out.println("Cannot find "+file+" image 
file:"+io.getClass().getName()+"-"+io.getMessage());
        } finally {
            try {
                if (is != null) is.close();
            } catch(IOException io) {
            }
        }
        return result;
    }


-- 
Oto 'tapik' Buchta, [EMAIL PROTECTED]
Senior Engineer, Systinet Corp,
http://www.systinet.com

Odpovedet emailem