Results 1 to 8 of 8

Thread: java path ..

  1. #1
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

    Default java path ..

    if im usenig win i can load this file easy by using this path

    Java Code:
    Properties props = lp.getProperties("C:\\Hagay\\file.properties");
    ;
    im in Ubuntu and trying this command
    and receiving exception


    Java Code:
      Properties props = lp.getProperties("home\\mikmik\\file.properties");
    what is the correct why to do it ...

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by miko5054 View Post
    if im usenig win i can load this file easy by using this path

    Java Code:
    Properties props = lp.getProperties("C:\\Hagay\\file.properties");
    ;
    im in Ubuntu and trying this command
    and receiving exception


    Java Code:
      Properties props = lp.getProperties("home\\mikmik\\file.properties");
    what is the correct why to do it ...
    Use slashes instead of backslashes on a Unix machine; it works on MS Windows machines too.

    kind regards,

    Jos

  3. #3
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

    Default

    thanks for the privous help now im using this class

    Java Code:
       public class PropertiesLoader {
    
    	
    	
    
    	public Properties getProperties(String pathToPropertiesFile) {
    		Properties properties = new Properties(); 
    		try { 
    			properties.load(new FileInputStream( pathToPropertiesFile )); 
    		} 
    		catch (IOException e) 
    		{ 
    			e.printStackTrace();
    			System.out.println("an exception occurred - an empty instance of Properties will be returned");
    		} 
    		return properties;
    	
    	}


    and from the main im trying to call the method like that...

    Java Code:
      public class DataBaseActionMain {
    public static void main(String[] args, String BankProperties) {
    PropertiesLoader loader = new PropertiesLoader();
    		Properties props = loader.getProperties("//home//mikmik//.java//Bank.properties");
    		
    		System.out.println( "customer_r_rank‬: " +props.getProperty("customer_r_rank‬")); 
    		System.out.println( "customer_g_rank‬: " +props.getProperty("customer_g_rank‬")); 
    		System.out.println( "customer_p_rank " +props.getProperty("customer_p_rank‬")); 
    		System.out.println( "regular_credit: " +props.getProperty("regular_credit‬")); 
    		System.out.println( "gold_credit: " +props.getProperty("gold_credit")); 
    		System.out.println( "platinuam_credit‬: " +props.getProperty("platinuam_credit")); 
    		
    	}
    }
    
    
    and than im receiving
    
    [CODE]  Exception in thread "main" java.lang.NoSuchMethodError: main
    what im doing wrong....
    [/CODE]

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    Can you post the commandline that generates that error?
    Does the class you're trying to execute have a main() method?

  5. #5
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

    Default

    i remove this code from the main line
    Java Code:
     String BankProperties
    and now im receiving this exception

    Java Code:
      java.io.FileNotFoundException: /home/mikmik/.java/Bank.properties (No such file or directory)an exception occurred - an empty instance of Properties will be returned
    customer_r_rank‬: null
    customer_g_rank‬: null
    
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(FileInputStream.java:137)
    	at java.io.FileInputStream.<init>(FileInputStream.java:96)
    	at dbexemple.PropertiesLoader.getProperties(PropertiesLoader.java:19)
    	at dbexemple.DataBaseActionMain.main(DataBaseActionMain.java:46)
    customer_p_rank null
    regular_credit: null
    gold_credit: null
    platinuam_credit‬: null

    i can see that is file FileNotFoundException but the file is in the corect path

    Java Code:
     Properties props = loader.getProperties("//home//mikmik//.java//Bank.properties");
    whats wrong now??

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    but the file is in the corect path
    Can you show the path to the file relative to the current directory and the classpath?
    Have you tried it without the leading /?

  7. #7
    miko5054 is offline Member
    Join Date
    Mar 2010
    Posts
    50
    Rep Power
    0

    Default

    if u meant the location of the file...
    this is it
    Java Code:
     /home/mikmik/.java/bank.properties
    and without the leading // give same result...

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by miko5054 View Post
    i remove this code from the main line
    Java Code:
     String BankProperties
    and now im receiving this exception

    Java Code:
      java.io.FileNotFoundException: /home/mikmik/.java/Bank.properties (No such file or directory)an exception occurred - an empty instance of Properties will be returned
    customer_r_rank‬: null
    customer_g_rank‬: null
    
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(FileInputStream.java:137)
    	at java.io.FileInputStream.<init>(FileInputStream.java:96)
    	at dbexemple.PropertiesLoader.getProperties(PropertiesLoader.java:19)
    	at dbexemple.DataBaseActionMain.main(DataBaseActionMain.java:46)
    customer_p_rank null
    regular_credit: null
    gold_credit: null
    platinuam_credit‬: null

    i can see that is file FileNotFoundException but the file is in the corect path

    Java Code:
     Properties props = loader.getProperties("//home//mikmik//.java//Bank.properties");
    whats wrong now??
    There's no need to use two forward slashes; uses just one as in "/home/mikmik/.java/Bank.properties". The forward slash is an ordinary character; the back slash isn't, i.e. it escapes the character following it (probably itself), so a single forward slash is enough.

    kind regards,

    Jos

Similar Threads

  1. setting class-path & Library Path in ubantu
    By programmer_007 in forum Eclipse
    Replies: 18
    Last Post: 02-22-2010, 12:31 PM
  2. File path validation in Java
    By aks123 in forum Advanced Java
    Replies: 2
    Last Post: 10-07-2009, 04:38 PM
  3. Replies: 3
    Last Post: 09-07-2009, 01:28 PM
  4. Java path variable's
    By Jordsk in forum New To Java
    Replies: 2
    Last Post: 04-09-2009, 02:20 AM
  5. Setting Java Path
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-22-2007, 09:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •