本文整理匯總了Java中java.io.FileOutputStream.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java FileOutputStream.flush方法的具體用法?Java FileOutputStream.flush怎麽用?Java FileOutputStream.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.FileOutputStream
的用法示例。
在下文中一共展示了FileOutputStream.flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testExcel07
import java.io.FileOutputStream; //導入方法依賴的package包/類
@Test
public void testExcel07() throws IOException{
List<UserPlus> list = getData(0, 20000);
Map<String, String> map = new HashMap<String,String>();
map.put("msg", "用戶信息導出報表");
map.put("status", "導出成功");
long start = System.currentTimeMillis();
Workbook workbook = ExcelExportUtil.exportExcel07(UserPlus.class, list, map, true);
long end = System.currentTimeMillis();
System.out.println("耗時:" + (end - start ) + "毫秒");
FileOutputStream outputStream = new FileOutputStream("D:/test/user.xlsx");
workbook.write(outputStream);
if(SXSSFWorkbook.class.equals(workbook.getClass())){
SXSSFWorkbook wb = (SXSSFWorkbook)workbook;
wb.dispose();
}
outputStream.flush();
outputStream.close();
}
示例2: saveImg
import java.io.FileOutputStream; //導入方法依賴的package包/類
/**
* @param b Bitmap
* @return 圖片存儲的位置
*/
public static File saveImg(Bitmap b, String name) throws Exception {
String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "test/headImg/";
File mediaFile = new File(path + File.separator + name + ".jpg");
if (mediaFile.exists()) {
mediaFile.delete();
}
if (!new File(path).exists()) {
new File(path).mkdirs();
}
mediaFile.createNewFile();
FileOutputStream fos = new FileOutputStream(mediaFile);
b.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
b.recycle();
b = null;
System.gc();
// return mediaFile.getPath();
return mediaFile;
}
示例3: testWriteSimpleUnknown
import java.io.FileOutputStream; //導入方法依賴的package包/類
@Test
public void testWriteSimpleUnknown() throws Exception
{
FileOutputStream fout = null;
try
{
String dir = this.getClass().getResource("/").getFile();
List<MessageResourceEntry> messages = messages();
this.writer.createExcel(messages, new File(dir + "test-out-f.xlsx"), "abc");
}
finally
{
if (fout != null)
{
try
{
fout.flush();
fout.close();
}
finally
{
fout = null;
}
}
}
}
示例4: getResponseData
import java.io.FileOutputStream; //導入方法依賴的package包/類
@Override
protected byte[] getResponseData(HttpEntity entity) throws IOException {
if (entity != null) {
InputStream instream = entity.getContent();
long contentLength = entity.getContentLength();
FileOutputStream buffer = new FileOutputStream(getTargetFile(), this.append);
if (instream != null) {
try {
byte[] tmp = new byte[BUFFER_SIZE];
int l, count = 0;
// do not send messages if request has been cancelled
while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
count += l;
buffer.write(tmp, 0, l);
sendProgressMessage(count, contentLength);
}
} finally {
AsyncHttpClient.silentCloseInputStream(instream);
buffer.flush();
AsyncHttpClient.silentCloseOutputStream(buffer);
}
}
}
return null;
}
示例5: getResponseData
import java.io.FileOutputStream; //導入方法依賴的package包/類
@Override
protected byte[] getResponseData(HttpEntity entity) throws IOException {
if (entity != null) {
InputStream instream = entity.getContent();
long contentLength = entity.getContentLength() + current;
FileOutputStream buffer = new FileOutputStream(getTargetFile(), append);
if (instream != null) {
try {
byte[] tmp = new byte[BUFFER_SIZE];
int l;
while (current < contentLength && (l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
current += l;
buffer.write(tmp, 0, l);
sendProgressMessage(current, contentLength);
}
} finally {
instream.close();
buffer.flush();
buffer.close();
}
}
}
return null;
}
示例6: batchesExport
import java.io.FileOutputStream; //導入方法依賴的package包/類
/**
* 分批寫出20w條數據
*
* @throws IOException
*/
@Test
public void batchesExport() throws IOException {
Map<String, String> map = new HashMap<String,String>();
map.put("msg", "用戶信息導出報表");
map.put("status", "導出成功");
Workbook workbook = null;
//分兩次寫入20w條數據
List<UserPlus> list;
for(int i = 0 ; i < 2 ; i++){
list = getData(i*100000, 100000);
workbook = ExcelExportUtil.exportExcel03(UserPlus.class, list, map,workbook);
}
FileOutputStream outputStream = new FileOutputStream("D:/test/user1.xls");
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
}
示例7: saveBitmap
import java.io.FileOutputStream; //導入方法依賴的package包/類
/**
* 保存Image的方法,有sd卡存儲到sd卡,沒有就存儲到手機目錄
*
* @param fileName
* @param bitmap
*/
public File saveBitmap(String dirsName, String fileName, Bitmap bitmap) {
if (bitmap == null) {
return null;
}
try {
File file = createSDFile(dirsName, fileName);
FileOutputStream fos = new FileOutputStream(file);
String Type = fileName.substring(fileName.lastIndexOf(".") + 1)
.toUpperCase();
if ("PNG".equals(Type) || "png".equals(Type)) {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
} else {
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos);
}
fos.flush();
fos.close();
scannerFile(file.getPath());
return file;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例8: getResponseData
import java.io.FileOutputStream; //導入方法依賴的package包/類
@Override
protected byte[] getResponseData(HttpEntity entity) throws IOException {
if (entity != null) {
InputStream instream = entity.getContent();
long contentLength = entity.getContentLength() + current;
FileOutputStream buffer = new FileOutputStream(getTargetFile(), append);
if (instream != null) {
try {
byte[] tmp = new byte[BUFFER_SIZE];
int l;
while (current < contentLength && (l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
current += l;
buffer.write(tmp, 0, l);
sendProgressMessage((int) current, (int) contentLength);
}
} finally {
instream.close();
buffer.flush();
buffer.close();
}
}
}
return null;
}
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:25,代碼來源:RangeFileAsyncHttpResponseHandler.java
示例9: saveBitmap
import java.io.FileOutputStream; //導入方法依賴的package包/類
public static String saveBitmap(Bitmap bitmap, Bitmap.CompressFormat format,
int quality, File destFile) {
try {
FileOutputStream fos = new FileOutputStream(destFile);
if (bitmap.compress(format, quality, fos)) {
fos.flush();
fos.close();
}
if (bitmap != null && !bitmap.isRecycled()) {
bitmap.recycle();
}
return destFile.getAbsolutePath();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例10: run
import java.io.FileOutputStream; //導入方法依賴的package包/類
@Override
public void run() {
super.run();
try {
listener.zipStart();
long sumLength = 0;
// 獲取解壓之後文件的大小,用來計算解壓的進度
long ziplength = getZipTrueSize(zipFileString);
FileInputStream inputStream = new FileInputStream(zipFileString);
ZipInputStream inZip = new ZipInputStream(inputStream);
ZipEntry zipEntry;
String szName = "";
while ((zipEntry = inZip.getNextEntry()) != null) {
szName = zipEntry.getName();
if (zipEntry.isDirectory()) {
szName = szName.substring(0, szName.length() - 1);
File folder = new File(outPathString + File.separator + szName);
folder.mkdirs();
} else {
File file = new File(outPathString + File.separator + szName);
file.createNewFile();
FileOutputStream out = new FileOutputStream(file);
int len;
byte[] buffer = new byte[1024];
while ((len = inZip.read(buffer)) != -1) {
sumLength += len;
int progress = (int) ((sumLength * 100) / ziplength);
updateProgress(progress, listener);
out.write(buffer, 0, len);
out.flush();
}
out.close();
}
}
listener.zipSuccess();
inZip.close();
} catch (Exception e) {
listener.zipFail();
}
}
示例11: fileCreator
import java.io.FileOutputStream; //導入方法依賴的package包/類
private boolean fileCreator(Token ref) throws IOException{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(ref);
oos.flush();
oos.close();
if(mFile.canWrite()) {
FileOutputStream fos = new FileOutputStream(mFile,false);
fos.write(bos.toByteArray());
fos.flush();
fos.close();
return true;
}
return false;
}
示例12: dumpYUVData
import java.io.FileOutputStream; //導入方法依賴的package包/類
public void dumpYUVData(byte[] buffer, int len, String name) {
File f = new File(Environment.getExternalStorageDirectory().getPath() + "/tmp/", name);
if (f.exists()) {
f.delete();
}
try {
FileOutputStream out = new FileOutputStream(f);
out.write(buffer);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: saveSettings
import java.io.FileOutputStream; //導入方法依賴的package包/類
/**
* Save the settings to ideaquicknotes.xml
*/
public static boolean saveSettings(Element element) {
// Get an instane of XMLOutputter
XMLOutputter outputter = new XMLOutputter();
File settingsFile = getSettingsFile();
if (settingsFile != null) {
try {
QuickNotesManager mgr = QuickNotesManager.getInstance();
element.setAttribute("showlinenumbers", mgr.isShowLineNumbers() ? "Y" : "N");
element.setAttribute("toolbarlocation", String.valueOf(mgr.getToolbarLocation()));
element.setAttribute("wordwrap", mgr.isWordWrap() ? "Y" : "N");
element.setAttribute("filelocation", mgr.getFileLocation_default());
Font font = mgr.getNotesFont();
element.setAttribute("fontname", font.getFontName());
element.setAttribute("fontsize", String.valueOf(font.getSize()));
Color fontColor = mgr.getFontColor();
element.setAttribute("fontColorDefault", mgr.fontColor_default ? "Y" : "N");
element.setAttribute("fontColorRed", String.valueOf(fontColor.getRed()));
element.setAttribute("fontColorGreen", String.valueOf(fontColor.getGreen()));
element.setAttribute("fontColorBlue", String.valueOf(fontColor.getBlue()));
Color bgColor = mgr.getBackgroundColor();
element.setAttribute("bgColorDefault", mgr.isBackgroundColor_default() ? "Y" : "N");
element.setAttribute("bgColorRed", String.valueOf(bgColor.getRed()));
element.setAttribute("bgColorGreen", String.valueOf(bgColor.getGreen()));
element.setAttribute("bgColorBlue", String.valueOf(bgColor.getBlue()));
Color bgLineColor = mgr.getBackgroundLineColor();
element.setAttribute("bgLineColorShow", mgr.isShowBackgroundLines() ? "Y" : "N");
element.setAttribute("bgLineColorDefault", mgr.isBackgroundLineColor_default() ? "Y" : "N");
element.setAttribute("bgLineColorRed", String.valueOf(bgLineColor.getRed()));
element.setAttribute("bgLineColorGreen", String.valueOf(bgLineColor.getGreen()));
element.setAttribute("bgLineColorBlue", String.valueOf(bgLineColor.getBlue()));
Color lineNumberColor = mgr.getLineNumberColor();
element.setAttribute("lineNumberColorDefault", mgr.isLineNumberColor_default() ? "Y" : "N");
element.setAttribute("lineNumberColorRed", String.valueOf(lineNumberColor.getRed()));
element.setAttribute("lineNumberColorGreen", String.valueOf(lineNumberColor.getGreen()));
element.setAttribute("lineNumberColorBlue", String.valueOf(lineNumberColor.getBlue()));
FileOutputStream fos = new FileOutputStream(settingsFile);
outputter.setFormat(Format.getPrettyFormat()); // make it Pretty!!!
outputter.output(element, fos);
fos.flush();
fos.close();
} catch (IOException e) {
return false;
}
}
return true;
}
示例14: saveImage
import java.io.FileOutputStream; //導入方法依賴的package包/類
public void saveImage(Bitmap cropBitmap) {
try {
FileOutputStream fos = new FileOutputStream(mCroppedFile);
cropBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: copy
import java.io.FileOutputStream; //導入方法依賴的package包/類
private void copy(String src, String dest) throws IOException {
String[] fileNames = context.getAssets().list(src);
if (fileNames.length > 0) {
File file = new File(dest);
if (!file.exists()) {
file.mkdirs();
}
for (String fileName : fileNames) {
// assets 文件夾下的目錄
if (!TextUtils.isEmpty(src)) {
copy(src + File.separator + fileName, dest + File.separator + fileName);
} else { // assets 文件夾
copy(fileName, dest + File.separator + fileName);
}
}
} else {
publishProgress(getString(R.string.string_splash_copy) + src + " ...");
File outFile = new File(dest);
InputStream is = context.getAssets().open(src);
FileOutputStream fos = new FileOutputStream(outFile);
byte[] buffer = new byte[1024];
int byteCount;
while ((byteCount = is.read(buffer)) != -1) {
fos.write(buffer, 0, byteCount);
}
fos.flush();
is.close();
fos.close();
}
}