passion and relax

[JAVA] 21. 웹, 운영체제, 클래스 정보 본문

프로그래밍

[JAVA] 21. 웹, 운영체제, 클래스 정보

Grab Java 2024. 6. 7. 15:37

운영체제 정보 추출

System.getProperty("os.name");
[windows와 그 외 os의 분기 예]

String dotPath = "";
if (System.getProperty("os.name").toLowerCase().indexOf("win") < 0) {
    dotPath = "/usr/bin/dot";
} else {
    dotPath = "C:\\Program Files\\Graphviz 2.21\\bin\\dot";
}

 


web crawling

String urlAddr = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?id=9389682";
try {
    URL url = new URL(urlAddr);
    URLConnection urlC = url.openConnection();
    urlC.setUseCaches(false);
    urlC.connect();

    BufferedReader br =
                       new BufferedReader(new InputStreamReader(urlC.getInputStream()));
    String  temp;

    while( (temp = br.readLine()) != null ) {
          System.out.println(temp);
    }

    br.close();

} catch (Exception ex) {
    Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}

 


class naming information

myClass.getClass().getCanonicalName();   //패키지명.클래스명
myClass.getClass().getSimpleName();      //클래스명
myClass.getClass().toString();           //class 패키지명.클래스명