Veröffentlicht 10. August 200619 j Hallo, Ich habe folgendes Problem: Ich möchte auf einem Server eine Datei erstellen (Zugriffsrechte stimmen, Servername auch) public class network_nio { public static void main(String[] args) throws IOException { File file = new File("//BDC/nettrans/test.txt"); System.out.println(file.toURL()); URL url = file.toURL(); URLConnection con = url.openConnection(); con.connect(); OutputStream out = con.getOutputStream(); FileChannel writer = ((FileOutputStream) out).getChannel(); String test = "test"; ByteBuffer buf = ByteBuffer.wrap(test.getBytes()); writer.write(buf); writer.close(); } } Wenn die datei vorhanden ist kommt: Exception in thread "main" java.net.UnknownServiceException: protocol doesn't support output wenn sie nicht vorhanden ist: Exception in thread "main" java.io.FileNotFoundException: \\JS-GATE\nettrans\test.txt (Das System kann die angegebene Datei nicht finden) Wenn ich sie aber erstellen will mit URL url = file.toURL(); File doc = new File(url.doc); if (!doc.exists()) { doc.createNewFile(); } kommt: Exception in thread "main" java.io.IOException: Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch PS: das println ergibt: "file://JS-GATE/nettrans/test.txt" Meine Frage jetzt: liegt das am Protokoll oder hab ich irgendwo anders den Fehler ? PS2: Ein Knock-Knock-Programm soll es nicht werden.
11. August 200619 j win oder lin? - For UNIX platforms, the prefix of an absolute pathname is always "/". Relative pathnames have no prefix. The abstract pathname denoting the root directory has the prefix "/" and an empty name sequence. - For Microsoft Windows platforms, the prefix of a pathname that contains a drive specifier consists of the drive letter followed by ":" and possibly followed by "\\" if the pathname is absolute. The prefix of a UNC pathname is "\\\\"; the hostname and the share name are the first two names in the name sequence. A relative pathname that does not specify a drive has no prefix. quelle: http://java.sun.com/j2se/1.5.0/docs/api/ bigredeyes
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.