import java.util.*; import java.io.*; public class HelloWorldGetProperties { public static void main(String[] args) { try { Properties prop = new Properties(); // プロパティファイルからキーと値のリストを読み込みます prop.load(new FileInputStream("javahello.properties")); // "javahello.message"に設定されている値を取得します String message = prop.getProperty("javahello.message"); // "javahello.url"に設定されている値を取得します String url = prop.getProperty("javahello.url"); // 読み込んだ値を表示します System.out.println("メッセージ:" + message); System.out.println("URL:" + url); } catch (Exception e) { e.printStackTrace(); } } }
コンパイル系のエラー? プリミティブ型の変数の初期値が設定されていない場合に発生した。 boolean b; <<< error boolean b = false; <<< ok
try { // netstatコマンドを実行 Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("netstat"); // 結果を標準出力に書き出す Reader in = new InputStreamReader(process.getInputStream()); int c = -1; while ((c = in.read()) != -1) { System.out.print((char) c); } in.close(); } catch (Exception ex) { ex.printStackTrace(); }
引数のあるコマンドを実行する場合
String[] cmd = {"move", "a", "b"} Process process = runtime.exec(cmd);
Windows で実行する場合で、error=2 が返ってくる場合
String[] cmd = {"cmd.exe", "/C", "XXXXXX"} Process process = runtime.exec(cmd);
Linuxの場合は、出来上がったlib*.soを、ファイル/etc/ld.so.confか、環境変数LD_LIBRARY_PATHに指定されているディレクトリに置く。
java.lang.UnsatisfiedLinkError? が出る場合は以下を注意
loadLibrary でエラーの場合、LD_LIBRARY_PATH 関数呼び出しでエラーの場合、.so を生成するときのパッケージ名
Properties props = System.getProperties(); System.out.println(props.get("os.name"));
long | 64bit | 9223372036854775807 | -9223372036854775808 |
int | 32bit | 2147483647 | -2147483648 |
double | 64bit | 1.7976931348623157E308 | 4.9E-324 |
float | 32bit | 3.4028235E38 | 1.4E-45 |
JDK1.4以降ではXMLパーサが組み込まれている。 自分のパーサを通したい場合は以下のように引数を追加する
>java -Xbootclasspath/p:moke.jar;hoge.jar -classpath aa.jar .....
// 一緒にJARに格納している適当なファイル URL classURL = getClass().getClassLoader().getResource("file/data1.txt"); URLConnection conn = classURL.openConnection(); JarURLConnection jarConn = (JarURLConnection) conn; Manifest manifest = jarConn.getManifest(); Attributes attr = manifest.getMainAttributes(); String servletURL = attr.getValue("MOKEMOKE");
Linux
サーバ構築
Windows
Java
Program