using system properties
I was doing some coding that was creating files and changing directories inside a file. I did the work initially on a windows machine, tested on a windows machine and I don't think there was any talk of a Linux machine. So of course onto the Linux machine we go, my code popped up the white flag and promptly fell flat on its backside.
I had of course heard about the nastiness of backward and forward slashes and have been drawn into the Linux world recently but thanks to the beauty of Java and it's platform independency. I recently read somewhere (and blogged about it) that Java isn't platform independent it is a platform, which I suppose is a fair point but to which doesn't really seem to be a bad thing to me (apart from a touch of bloatyness). Anyway back to the subject.
http://scv.bu.edu/Doc/Java/tutorial/java/system/properties.html
There are a number of useful values in the System object and probably the most popular is the System.out.println that a lot people use for debugging their code.
Another useful item is the
"file.separator"
this will return the file separator used, so in my code I used this instead of using a backslash or forward slash, I used the
System.getProperty("file.separator")
this will return the different file separator used for the different operating systems. I'm sure a lot of people already know about the system properties but this was just one way I found to solve problems I had when saving and reading files on different operating system.
There are a number of useful values in the System object and probably the most popular is the System.out.println that a lot people use for debugging their code.
Another useful item is the
"file.separator"
this will return the file separator used, so in my code I used this instead of using a backslash or forward slash, I used the
System.getProperty("file.separator")
this will return the different file separator used for the different operating systems. I'm sure a lot of people already know about the system properties but this was just one way I found to solve problems I had when saving and reading files on different operating system.
2 Comments:
Hello
You can also use File.separator or File.separatorChar. Even better, you can use the File constructor which takes the parent File as an argument, rather than constructing path strings manually, e.g.:
File file = new File(directory, "myfile.txt");
James
By Unknown, at Wed Feb 14, 11:43:00 am 2007
Find at Java System properties an article on Java system properties and how to iterate and display them.
By Yan, at Tue May 31, 08:43:00 am 2011
Post a Comment
<< Home