Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Dateizugriff über Netzwerk

Empfohlene Antworten

Veröffentlicht

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.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.