當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。