当前位置: 首页>>代码示例>>Java>>正文


Java FileOutputStream.flush方法代码示例

本文整理汇总了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();
}
 
开发者ID:long47964,项目名称:excel-utils,代码行数:20,代码来源:TestUser.java

示例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;
        }
 
开发者ID:kaixuanluo,项目名称:pc-android-controller-android,代码行数:26,代码来源:ImageCompressUtil.java

示例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;
			}
		}
	}
}
 
开发者ID:namics,项目名称:spring-i18n-support,代码行数:27,代码来源:ExcelWriterTest.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:FileAsyncHttpResponseHandler.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:RangeFileAsyncHttpResponseHandler.java

示例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();
}
 
开发者ID:long47964,项目名称:excel-utils,代码行数:25,代码来源:TestUser.java

示例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;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:31,代码来源:FileUtils.java

示例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;
}
 
开发者ID:Hultron,项目名称:LifeHelper,代码行数:18,代码来源:UserActivity.java

示例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();
    }
}
 
开发者ID:codekongs,项目名称:ImageClassify,代码行数:41,代码来源:UnZipMainThread.java

示例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;
}
 
开发者ID:wax911,项目名称:anitrend-app,代码行数:16,代码来源:Cache.java

示例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();
  }
}
 
开发者ID:pedroSG94,项目名称:rtmp-rtsp-stream-client-java,代码行数:15,代码来源:YUVUtil.java

示例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;
}
 
开发者ID:jrana,项目名称:quicknotes,代码行数:56,代码来源:QuickNotesManager.java

示例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();
    }

}
 
开发者ID:Loofer,项目名称:Watermark,代码行数:12,代码来源:CropPresenter.java

示例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();
    }
}
 
开发者ID:shenhuanet,项目名称:Ocr-android,代码行数:31,代码来源:SplashActivity.java


注:本文中的java.io.FileOutputStream.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。