Results 1 to 3 of 3
- 08-18-2011, 05:25 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 2
- Rep Power
- 0
Change Literal String to File Path with speratorChar
I'm very very new to Java, and only been learning from reading things on the internet. So forgive me if this doesn't sound correct. I'll try my best. :)
First thing my code does is look at an XML file to find the installation path of some software. The path could be anything. (\\servername\share\restofpath\ or C:\Program Files\etc, so it could have a couple "\" or many)
At this point I've been able to open the file and create a variable that contains the path I'm looking for.
For example:
Java Code:String filepath = "C:\Program Files\Program Name\"; System.out.println(filepath);
C:\Program Files\Program Name\
I'm trying to check to see if that folder is writable. When I try the following it doesn't work.
Java Code:File checkfile = new File ("filepath"); boolean isExecutable = checkfile.canWrite(); if (isExecutable) { System.out.println("Folder is writable"); } else { System.out.println("Folder is read only"); }
I'm assuming I need to change my String filepath = "C:\Program Files\Program Name\" to something like
filepath = "C:" + File.separatorChar + "Program Files" + File.separatorChar + "Program Name";
What would be the best way to convert this? (keep in mind the length and number of seperatorChar's could be very long with lots of seperators)
Thanks for any tips, and also please let me know if you need any additional information.Last edited by Jeremiah; 08-18-2011 at 05:44 PM.
- 08-18-2011, 05:51 PM #2File checkfile = new File ("filepath");
If the later, remove the "s
- 08-18-2011, 07:14 PM #3
Member
- Join Date
- Aug 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Filtering with Pattern, use metacharacters as a literal
By nenadm in forum Advanced JavaReplies: 2Last Post: 02-04-2011, 10:10 PM -
Change to string
By PhQ in forum New To JavaReplies: 7Last Post: 04-14-2010, 03:26 PM -
What is the difference between Inline literal and Static final String in Java.
By devaru2003 in forum Advanced JavaReplies: 3Last Post: 03-26-2010, 07:09 AM -
Why doesnt the sound play when I change the path?
By ProGenius in forum New To JavaReplies: 10Last Post: 12-22-2009, 04:58 PM -
Regex - matching literal characters
By racha0601 in forum Advanced JavaReplies: 3Last Post: 04-07-2009, 11:25 PM
Bookmarks