2010年8月30日月曜日

JFreeChart一般概論 ファイル保存

JFreeChartと格闘中ですが以下の3つの操作で表示させます。

JSP側の処理
⇒application.getRealPath()によりWEB-INFのパスをドライブからのパスに変換する
(例 mychart.setRealPath(application.getRealPath);)                                  //build/web

JavaBeans側の処理
⇒tempにコピーされた*****.jpgを以下のコピー関数でJSPカレントフォルダへコピー
(例 copyTransfer(tempFolder, realPath);)

JSP側でカレントフォルダの画像を見に行く

/**
* コピー元のパス[srcPath]から、コピー先のパス[destPath]へ
* ファイルのコピーを行います。
* コピー処理にはFileChannel#transferToメソッドを利用します。
* 尚、コピー処理終了後、入力・出力のチャネルをクローズします。
* @param srcPath コピー元のパス
* @param destPath コピー先のパス
* @throws IOException 何らかの入出力処理例外が発生した場合
*/
public static void copyTransfer(String srcPath, String destPath)
throws IOException {

FileChannel srcChannel = new
FileInputStream(srcPath).getChannel();
FileChannel destChannel = new
FileOutputStream(destPath).getChannel();
try {
srcChannel.transferTo(0, srcChannel.size(), destChannel);
} finally {
srcChannel.close();
destChannel.close();
}

}

0 件のコメント:

コメントを投稿