libgcj on win32 (mingw) - target: java.io.File.listRoots(); doesn't work

Erik Poupaert erik.poupaert@chello.be
Sun Feb 23 19:33:00 GMT 2003


>>>>> does anybody have an idea how I can get this working? I don't have any
>>>>> know-how in gcc/gcj hacking myself so I'm stuck with it.

The SWT fileviewer example contains a workaround that you can rip ad
libidum. It's excessively ugly, but I guess it's about the only way to make
these things work (on the JDK as well):

	/**
	 * Gets filesystem root entries
	 *
	 * @return an array of Files corresponding to the root directories on the
platform,
	 *         may be empty but not null
	 */
	File[] getRoots() {
		/*
		 * On JDK 1.22 only...
		 */
		// return File.listRoots();

		/*
		 * On JDK 1.1.7 and beyond...
		 * -- PORTABILITY ISSUES HERE --
		 */
		if (System.getProperty ("os.name").indexOf ("Windows") != -1) {
			Vector /* of File */ list = new Vector();
			list.add(new File(DRIVE_A));
			list.add(new File(DRIVE_B));
			for (char i = 'c'; i <= 'z'; ++i) {
				File drive = new File(i + ":" + File.separator);
				if (drive.isDirectory() && drive.exists()) {
					list.add(drive);
					if (initial && i == 'c') {
						currentDirectory = drive;
						initial = false;
					}
				}
			}
			File[] roots = (File[]) list.toArray(new File[list.size()]);
			sortFiles(roots);
			return roots;
		} else {
			File root = new File(File.separator);
			if (initial) {
				currentDirectory = root;
			}
			return new File[] { root };
		}
	}



More information about the Java mailing list