Getting Error Creating Directory In Ubuntu Using Java -
I have created a test case of a method that will call it the actual method and execute it.
Actual method:
public string GetDefaultFolderPath () {string path = ""; Try {String os = System.getProperty ("os.name"); System.out.println ("OS name identification"); If (os.toUpperCase (). IndexOf ("WINDOWS") = -1) {file file = new file ("C: / MARCDictionary"); If (! File.exists ()) {System.out.println ("11"); File.mkdir (); } Path = "C: / MARCDictionary"; } Else if (os.toUpperCase (). IndexOf ("LINUX") = -1) {file file = new file ("/ usr / MARCDictionary"); If (! File.exists ()) {System.out.println ("22"); //file.mkdir (); File.createNewFile (); } Path = "/ usr / MARCDictionary"; }} Hold (exception e) {e.printStackTrace (); } return path; }
Test case:
@Test public void Testgetdifoltfolderpath () {System.out.println ( "getDefaultFolderPath"); Utilities Example = Utilities.Instance (); String Express = "/ usr / MARCDictionary"; String result = instance.getDefaultFolderPath (); Emphasis (express results, results); }
gives me an error:
getDefaultFolderPath OS name identified 22 java.io.IOException: permission denied on java.io.UnixFileSystem.createFileExclusively the (Native utilities.NGLUtilitiesTest.testGetDefaultFolderPath (UtilitiesTest.java:85) on java.io.File.createNewFile (File.java:1006) NGLUtility.NGLUtilities.getDefaultFolderPath (Utilities.java:108) on org.junit.ComparisonFailure Method): Expectancy: / usr / MARCDictionary
Any suggestion please, why this is happening ..
I am using Ubuntu
and IntelliJ idea.
After
write to your program / usr The directory should allow you to write permissions on this folder or write to the other code inside
/ usr
which is allowed to write. You can use chmod 777 / usr
to give all the permissions on the / usr
for example, hope it helps < / P>
Comments
Post a Comment