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


Java FileOutputStream.close方法代码示例

本文整理汇总了Java中java.io.FileOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java FileOutputStream.close方法的具体用法?Java FileOutputStream.close怎么用?Java FileOutputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.FileOutputStream的用法示例。


在下文中一共展示了FileOutputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: copyTileAsset

import java.io.FileOutputStream; //导入方法依赖的package包/类
/**
 * Copy the file from the assets to the map tiles directory if it was
 * shipped with the APK.
 */
public static boolean copyTileAsset(Context context, String filename) {
    if (!hasTileAsset(context, filename)) {
        // file does not exist as asset
        return false;
    }

    // copy file from asset to internal storage
    try {
        InputStream is = context.getAssets().open(TILE_PATH + File.separator + filename);
        File f = getTileFile(context, filename);
        FileOutputStream os = new FileOutputStream(f);

        byte[] buffer = new byte[1024];
        int dataSize;
        while ((dataSize = is.read(buffer)) > 0) {
            os.write(buffer, 0, dataSize);
        }
        os.close();
    } catch (IOException e) {
        return false;
    }

    return true;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:29,代码来源:MapUtils.java

示例2: writeToFile

import java.io.FileOutputStream; //导入方法依赖的package包/类
public void writeToFile(ArrayList<String> list, String fileName)
{
    try
    {
        FileOutputStream stream = this.openFileOutput(fileName,Context.MODE_PRIVATE);

        for (String item : list)
        {
            stream.write((item + "\n").getBytes());
        }
        stream.close();
    }
    catch (Exception e)
    {

    }
}
 
开发者ID:lanceeeaton,项目名称:Text-Rabbit,代码行数:18,代码来源:Game.java

示例3: saveNamedDataToFile

import java.io.FileOutputStream; //导入方法依赖的package包/类
public boolean saveNamedDataToFile(final String name, final File file)
        throws IOException {
    synchronized (this) {
        if (updateNameData.indexOf(name) < 0)
            updateNameData.add(name);
        files.put(name, file);
        if (file.exists())
            return true;
        final InputStream is = getNamedData(name);
        if (is == null)
            return false;
        file.getParentFile().mkdirs();
        final FileOutputStream fos = new FileOutputStream(file);
        copyStream(is, fos);
        fos.close();
        return true;
    }
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:19,代码来源:AbstractDataPlugin.java

示例4: createJarArchive

import java.io.FileOutputStream; //导入方法依赖的package包/类
public static void createJarArchive(JavaProjectFolder projectFolder) throws IOException {
    //input file
    File dirBuildClasses = projectFolder.getDirBuildClasses();
    File archiveFile = projectFolder.getOutJarArchive();


    // Open archive file
    FileOutputStream stream = new FileOutputStream(archiveFile);
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");

    //Create the jar file
    JarOutputStream out = new JarOutputStream(stream, manifest);

    //Add the files..
    if (dirBuildClasses.listFiles() != null) {
        for (File file : dirBuildClasses.listFiles()) {
            addzz(dirBuildClasses.getPath(), file, out);
        }
    }

    out.close();
    stream.close();
    System.out.println("Adding completed OK");
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:26,代码来源:Jar.java

示例5: copy

import java.io.FileOutputStream; //导入方法依赖的package包/类
private static void copy(String src, String dest) throws IOException {

        File inputFile  = new File(src);
        File outputFile = new File(dest);

        if (!inputFile.exists()) {
            return;
        }

        FileInputStream  in  = new FileInputStream(inputFile);
        FileOutputStream out = new FileOutputStream(outputFile);
        int              c;

        while ((c = in.read()) != -1) {
            out.write(c);
        }

        in.close();
        out.close();
    }
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:21,代码来源:TestKarl.java

示例6: sizeCompress

import java.io.FileOutputStream; //导入方法依赖的package包/类
/**
 * 4.尺寸压缩(通过缩放图片像素来减少图片占用内存大小)
 *
 * @param bmp
 * @param file
 */

public static void sizeCompress(Bitmap bmp, File file) {
    // 尺寸压缩倍数,值越大,图片尺寸越小
    int ratio = 8;
    // 压缩Bitmap到对应尺寸
    Bitmap result = Bitmap.createBitmap(bmp.getWidth() / ratio, bmp.getHeight() / ratio, Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Rect rect = new Rect(0, 0, bmp.getWidth() / ratio, bmp.getHeight() / ratio);
    canvas.drawBitmap(bmp, null, rect, null);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // 把压缩后的数据存放到baos中
    result.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    try {
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(baos.toByteArray());
        fos.flush();
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:chenliguan,项目名称:Android-BitherCompress-master,代码行数:29,代码来源:NativeUtil.java

示例7: createPropertiesFiles

import java.io.FileOutputStream; //导入方法依赖的package包/类
private String[] createPropertiesFiles() throws IOException {
  String[] files = new String[] {"storeProps.props", "readerProps.props", "writerProps.props"};
  FileOutputStream fosStoreProps = new FileOutputStream(files[0]);
  FileOutputStream fosReaderProps = new FileOutputStream(files[1]);
  FileOutputStream fosWriterProps = new FileOutputStream(files[2]);

  fosStoreProps.write(Bytes.toBytes("store.prop.prop1=value1\n"));
  fosStoreProps.write(Bytes.toBytes("store.prop.prop2=value11\n"));
  fosReaderProps.write(Bytes.toBytes("store.reader.prop.prop1=value2\n"));
  fosReaderProps.write(Bytes.toBytes("store.reader.prop.prop2=value22\n"));
  fosWriterProps.write(Bytes.toBytes("store.writer.prop.prop1=value3\n"));
  fosWriterProps.write(Bytes.toBytes("store.writer.prop.prop2=value33\n"));

  fosStoreProps.close();
  fosReaderProps.close();
  fosWriterProps.close();

  return files;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:FTableCommandsDUnitTest.java

示例8: goToNextTest

import java.io.FileOutputStream; //导入方法依赖的package包/类
public void goToNextTest(boolean wasRight)  {
    //Create scores file because this is the first test
    try {
        FileOutputStream fos = openFileOutput("scores.txt", Context.MODE_APPEND);
        if (wasRight) {
            Toast.makeText(TestActivity1.this, "Correct", Toast.LENGTH_SHORT).show();
            fos.write("1\n".getBytes());
        } else {
            Toast.makeText(TestActivity1.this, "Wrong", Toast.LENGTH_SHORT).show();
            fos.write("0\n".getBytes());
        }
        fos.close();
        Intent test2 = new Intent(TestActivity1.this, TestActivity2.class);
        startActivity(test2);
    }catch (Exception e){
    }
    testTime = false;
    finish();

}
 
开发者ID:PiSimo,项目名称:Mens,代码行数:21,代码来源:TestActivity1.java

示例9: copyFile

import java.io.FileOutputStream; //导入方法依赖的package包/类
static int copyFile(File sourceFile, File destFile, boolean save) {
    int i=-1;
    try{
        if (!sourceFile.exists()) {
            return i+1;
        }
        if (!destFile.exists()) {
            if(save)i=i+2;
            destFile.createNewFile();
        }
        FileChannel source;
        FileChannel destination;
        FileInputStream fileInputStream = new FileInputStream(sourceFile);
        source = fileInputStream.getChannel();
        FileOutputStream fileOutputStream = new FileOutputStream(destFile);
        destination = fileOutputStream.getChannel();
        if (destination != null && source != null) {
            destination.transferFrom(source, 0, source.size());
            i=2;
        }
        if (source != null) {
            source.close();
            i=3;
        }
        if (destination != null) {
            destination.close();
            i=4;
        }
        fileInputStream.close();
        fileOutputStream.close();
    }catch (Exception e)
    {
        System.err.println("Error saving preferences: " + e.getMessage());
        Log.e(e.getMessage(), e.toString());
    }
    return i;
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:38,代码来源:Utilities.java

示例10: testOutput

import java.io.FileOutputStream; //导入方法依赖的package包/类
public byte[] testOutput(byte[] pData,String pName){
    try {
        FileOutputStream F = new FileOutputStream(new File(pName));
        F.write(pData);
        F.close();
    }catch (Exception e){}
    return pData;
}
 
开发者ID:xjboss,项目名称:MCRenderCrashFix,代码行数:9,代码来源:RenderClassesProcess.java

示例11: saveTempPicture

import java.io.FileOutputStream; //导入方法依赖的package包/类
public static void saveTempPicture(String filePath,String fileTempPath){
    File file = new File(fileTempPath);
    Bitmap bmp = PictureUtil.getSmallBitmap(filePath,120,120);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // 把压缩后的数据存放到baos中
    bmp.compress(Bitmap.CompressFormat.PNG, 10, baos);
    try {
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(baos.toByteArray());
        fos.flush();
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:16,代码来源:PictureUtil.java

示例12: finishWrite

import java.io.FileOutputStream; //导入方法依赖的package包/类
/**
 * Call when you have successfully finished writing to the stream
 * returned by {@link #startWrite()}.  This will close, sync, and
 * commit the new data.  The next attempt to read the atomic file
 * will return the new file stream.
 */
public void finishWrite(FileOutputStream str) {
    if (str != null) {
        sync(str);
        try {
            str.close();
            mBackupName.delete();
        } catch (IOException e) {
            Log.w("AtomicFile", "finishWrite: Got exception:", e);
        }
    }
}
 
开发者ID:codehz,项目名称:container,代码行数:18,代码来源:AtomicFile.java

示例13: FS_PeakClusterWrite

import java.io.FileOutputStream; //导入方法依赖的package包/类
private void FS_PeakClusterWrite() {
    try {
        Logger.getRootLogger().info("Writing PeakCluster serialization to file:" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.serFS...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.serFS", false);
        FSTObjectOutput out = new FSTObjectOutput(fout);
        out.writeObject(PeakClusters);
        out.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        JavaSerializationPeakClusterWrite();
    }
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:14,代码来源:LCMSPeakBase.java

示例14: fileSeperate

import java.io.FileOutputStream; //导入方法依赖的package包/类
public static void fileSeperate(File file, int number, String suffix) throws Exception {

		destPath = file.getParentFile().toString() + File.separator
				+ file.getName().substring(0, file.getName().indexOf("."));
		destFile = new File(destPath);
		if (!destFile.exists()) {
			destFile.mkdirs();
		}
		outInfoFile = new File(destFile, file.getName().substring(0, file.getName().indexOf(".")) + suffix + ".txt");
		outInfo = new FileWriter(outInfoFile);
		inSource = new FileInputStream(file);
		long fileLength = file.length();
		long size = fileLength / number + 1;
		long eIndex = 0;
		long bIndex = 0;
		for (int i = 0; i < number; i++) {
			outFile = new File(destFile,
					file.getName().substring(0, file.getName().indexOf(".")) + "part" + i + suffix);
			outDest = new FileOutputStream(outFile);
			eIndex += size;
			eIndex = (eIndex > fileLength) ? fileLength : eIndex;
			while (bIndex < eIndex) {
				outDest.write(inSource.read());
				bIndex++;
			}
			outInfo.write(outFile.getAbsolutePath());
			outInfo.write(System.getProperty("line.separator"));
			outInfo.flush();
		}
		outDest.close();
		outInfo.close();
		inSource.close();
	}
 
开发者ID:lslxy1021,项目名称:FileOperation,代码行数:34,代码来源:Segment.java

示例15: getQrcode

import java.io.FileOutputStream; //导入方法依赖的package包/类
/**
 * 换取二维码
 *
 * @param qrcodeFile 二维码存储路径
 */
public void getQrcode(String qrcodeFile) {
	try {
		byte[] b = HttpUtils.getFile(SHOWQRCODE_POST_URL + URLEncoder.encode(ticket, "UTF-8"));
		File file = new File(qrcodeFile);
		FileOutputStream fStream = new FileOutputStream(file);
		fStream.write(b);
		fStream.flush();
		fStream.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:funtl,项目名称:framework,代码行数:18,代码来源:Qrcode.java


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