2017-07-07 68 views
0

如何生成具有屬性文件如何生成具有屬性文件

public class Download_logfiles { 
/** 
* Download_logfiles class has to be public because another class uses the 
* Download_logfiles class 
*/ 

private static URL URLObj; 
/** 
* variable set for the server links from which the log files to be 
* downloaded 
*/ 
private static URLConnection connect; 
/** Variable for URL connection */ 
static String filename = ""; 
/** Variable used for extracting the servers */ 
static String user = ""; 
/** Variable used for user id */ 
static String pass = ""; 
/** Variable used for password */ 

static String download = ""; 
static Set<String> urls = new HashSet<String>(); 
static Set<String> comp = new HashSet<String>(); 
static Set<String> envir = new HashSet<String>(); 
static Properties prop = new Properties(); 

public static void main(String[] args) 
     throws IOException { /** program entry point */ 

    System.out.println("argument count:" + args.length + " content:" + args); 

    if(args.length==0) 
    { 
     System.out.println("Please enter the property file via arguments!!!"); /**Go to run configuration and under arguements enter the path **/ 
     System.exit(0); 
    } 

    readConfigProperties(args[0]); 
    configUIParameter(); 
    Hashtable<String, String> loginfo = Validation(); 
    String componentavx = loginfo 
      .get("component"); /** extract component information */ 
    String environmentProd = loginfo 
      .get("environment"); /** extract environment information */ 
    config(componentavx, environmentProd); 
    user = loginfo.get(
      "user"); /** extract login information from the property file */ 
    pass = loginfo.get("pass"); 

    try { /** Usage of Try catch handlers */ 
     String currentURL; 
     Iterator<String> iter = urls.iterator(); 
     System.out.println(iter); 

     while (iter.hasNext()) { /** Start iterating over URLs */ 

      currentURL = iter.next(); 
      StringTokenizer st = new StringTokenizer(currentURL, 
        "/."); /** 
          * The string tokenizer class allows an 
          * application to break a string into tokens 
          */ 
      st.nextToken(); 
      String filePrefix = st.nextToken(); 
      System.out.println("Url: " + currentURL); 

      boolean moreFilesAvailable = true; /** 
               * check condition for all 
               * log files available in 
               * the server 
               */ 

      for (int i = 0; moreFilesAvailable; i++) { 

       File file = null; 

       if (i != 0) { /** Handle the condition */ 
        URLObj = new URL(currentURL + filename + "." + i); 

       } else { 
        URLObj = new URL(currentURL + filename); 

       } 
+0

請幫我這個 –

+0

阿茲米,閱讀這個問題和答案https://stackoverflow.com/questions/2815404/load-properties-file-in-jar – MikhAn

回答

0

您需要的路徑傳遞到您的文件屬性爲Java程序的jar文件Java程序的jar文件使用-D

-Dname=$pathto yourjar anyargs.. 

JVM你可以在你的應用程序得到它likethis:

String location = System.getProperty(name); 
+0

對不起但我無法承諾..請簡單解釋一下......它的要求@Frank –

相關問題