Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Windows nul drive test
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/*
* Author: Ashwin Jayaprakash / Date: Jul 20, 2010 / Time: 10:00:22 PM / Contact: http://www.ashwinjayaprakash.com
*/
public class DevNullTest {
public static void main(String[] args) throws IOException {
File f = new File("nul:");
System.out.println(f + " write: " + f.canWrite() + ", read: " + f.canRead()
+ ", exec: " + f.canExecute() + ", length: " + f.length()
+ ", dirs: " + f.list() + ", mkdirs: " + f.mkdirs()
+ ", path: " + f.getAbsolutePath());
System.out.println("----------");
File f2 = new File("nul:test.log");
FileOutputStream fos = new FileOutputStream(f2);
for (int i = 0; i < 1024; i++) {
fos.write(1);
}
fos.close();
System.out.println(
"Wrote to: " + f2 + " write: " + f2.canWrite() + ", read: " + f2.canRead()
+ ", exec: " + f2.canExecute() + ", length: " + f2.length()
+ ", dirs: " + f2.list() + ", mkdirs: " + f2.mkdirs()
+ ", path: " + f2.getAbsolutePath());
System.out.println("----------");
File f3 = new File(f, "another.log");
try {
boolean b = f3.createNewFile();
System.out.println(f3);
}
catch (IOException e) {
System.err.println("createNewFile() failed on: " + f3);
e.printStackTrace();
}
System.out.println("----------");
File f4 = new File(f, "again.log");
System.out.println(f4 + " write: " + f4.canWrite() + ", read: " + f4.canRead()
+ ", exec: " + f4.canExecute() + ", length: " + f4.length()
+ ", dirs: " + f4.list() + ", mkdirs: " + f4.mkdirs()
+ ", path: " + f4.getAbsolutePath());
}
}
nul: write: true, read: true, exec: true, length: 0, dirs: null, mkdirs: true, path: D:\Dump\nul:
----------
Wrote to: nul:test.log write: true, read: true, exec: true, length: 0, dirs: null, mkdirs: true, path: D:\Dump\nul:test.log
----------
createNewFile() failed on: nul:\another.log
java.io.IOException: The filename, directory name, or volume label syntax is incorrect
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)
at com.athi.bala.test.DevNullTest.main(DevNullTest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
----------
nul:\again.log write: false, read: false, exec: false, length: 0, dirs: null, mkdirs: false, path: D:\Dump\nul:\again.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment