Zum Inhalt springen

Dateizugriff über Netzwerk


Empfohlene Beiträge

Geschrieben

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.

Geschrieben

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

Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde Dich hier an.

Jetzt anmelden

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...