SSブログ

スポンサーリンク


Javaの豆知識 「ファイル作成処理」 [備忘録]

import java.io.IOException;
/**
* @author Shu_mei
*
*/
public class UploadObjectTest {

 public static void main(String[] args) {
  String text = new String("友の死\n寺田屋大騒動");
  UploadObject upload = new UploadObject("C:/temp/", ".txt", text.getBytes());
  try {
   upload.FileOut("test");
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}

import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author shu_mei
* ファイル作成クラス
*/
public class UploadObject {
 private byte uploadData_[];

 private String strContentType_;

 private String strDirectoryName_;

 public UploadObject(String strDirectoryName, String strContentType, byte uploadData[]) {
  strContentType_ = strContentType;
  strDirectoryName_ = strDirectoryName;
  uploadData_ = uploadData;
 }

 public void FileOut(String strFileName) throws IOException {
  FileOutputStream fos = null;
  try {
   fos = new FileOutputStream(strDirectoryName_.concat(strFileName).concat(strContentType_));
fos.write(uploadData_);
  } catch (Exception e) {
   throw new IOException(e.getMessage());
  } finally {
   if (fos != null) {
    fos.flush();
    fos.close();
   }
  }
 }
}


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 0

コメント 0

コメントを書く

お名前:[必須]
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

Facebook コメント

トラックバック 0



スポンサーリンク