本文整理匯總了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;
}
示例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)
{
}
}
示例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;
}
}
示例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");
}
示例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();
}
示例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();
}
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
}
}
示例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();
}
}
示例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();
}
示例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();
}
}