スポンサーリンク
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();
}
}
}
}
Facebook コメント
スポンサーリンク
コメント 0