備忘録 Subversion
■java.new.URLクラス
リモートファイルもローカルファイルも同一のアクセスが可能。
サンプルソース
import java.io.*;
import java.net.*;
class TestUrl{
public static void main(String args){
BufferedReader reader = null;
try{
URL url = new URL("http://www26.atwiki.jp/kerikerikeri/pages/26.html");
reader = new BufferedReader(new InputStreamReader(url.openStream(),"UTF-8"));
while((line=reader.readLine()) != null){
System.out.println(line);
}
}catch(Exception e){
}
}
■DataHandlerクラス
SOAP Attachmentで使うDataHandlerクラスを使ってみる。
実装サンプル
import javax.activation.*;
import java.io.*;
FileDataSource fds = new FileDataSource(new File("パス","ファイル名"));
/** DataHandler生成 */
DataHandler dh = new DataHandler(fds);
/** byte[]に格納 */
ByteArrayOutputStream baos = new ByteArrayOutputStream();
dh.getOutputStream(baos);
byte[] b = baos.toByteArray();
■ミリ秒を表示する
java.util.Dateクラス
java.text.DateFormatクラス
java.text.SimpleDateFormatクラス
Date date = new Date();
DateFormat dateformat = new SimpleDateFormat("yyyyMMdd HH:mm:ss.SSS");
dateformat.format(date);
実行結果
20070217 01:55:24.499
最終更新:2008年04月29日 13:18