Also, lange her - will jedoch erklären, wie ich es gelöst habe.
ich habe ein Java-Applet geschrieben. Sehr einfach:
Code:
import java.applet.Applet;
import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.UUID;
import javax.swing.JOptionPane;
@SuppressWarnings("serial")
public class appopen extends Applet {
@Override
public void init() {
}//ENDE function..
//Öffnet Datei aus p_path..
public void openFile (String p_path) {
String pathToFile = p_path;
File file = null;
URL fileURL = null;
Desktop desktop = null;
int FileNameLength = pathToFile.length();
String trimedFile = pathToFile.trim().substring(0, 4);
if (trimedFile.equals("http")) {
try {
fileURL = new URL(pathToFile);
URLConnection urlc = fileURL.openConnection();
InputStream is = urlc.getInputStream();
UUID uuid = UUID.randomUUID();
String tmpFileName = uuid.toString();
int lastDotPosition = pathToFile.lastIndexOf(".");
String FileEndung = pathToFile.substring(lastDotPosition, FileNameLength);
//String tmpFolder = System.getProperty("TMP"); //In Sys-Var tmp-Ordner
file = new File("C:\\temp\\" + tmpFileName + "." + FileEndung);
FileOutputStream os = new FileOutputStream(file);
copy( is, os );
if ( is != null )
try { is.close(); } catch ( IOException e ) { }
if ( os != null )
try { os.close(); } catch ( IOException e ) { }
} catch (Exception e1) {
System.out.print("Bei URL-Convert \n" + e1.getMessage());
JOptionPane.showMessageDialog(null, "FEHLER \n" + e1.getMessage(), "Fehler", JOptionPane.OK_OPTION);
}
} else {
file = new File(pathToFile);
}
try {
desktop = Desktop.getDesktop();
desktop.open(file);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Die Datei " + pathToFile + " konnte nicht geöffnet werden \n" + e.getMessage(), "Fehler beim Öffnen", JOptionPane.OK_CANCEL_OPTION);
}
}//ENDE function..
static void copy( InputStream in, OutputStream out ) throws IOException
{
byte[] buffer = new byte[ 0xFFFF ];
for ( int len; (len = in.read(buffer)) != -1; )
try {
out.write( buffer, 0, len );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Ist vielleicht nicht der beste Code, aber ich denke für mein ersten Applet schon OK.
Gruß