當前位置: 首頁>>代碼示例>>Java>>正文


Java FileOutputStream.write方法代碼示例

本文整理匯總了Java中java.io.FileOutputStream.write方法的典型用法代碼示例。如果您正苦於以下問題:Java FileOutputStream.write方法的具體用法?Java FileOutputStream.write怎麽用?Java FileOutputStream.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.FileOutputStream的用法示例。


在下文中一共展示了FileOutputStream.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: downloadAndStore

import java.io.FileOutputStream; //導入方法依賴的package包/類
private void downloadAndStore(String url, CacheEntry cacheEntry) throws IOException {
    Log.d(TAG, Thread.currentThread().getStackTrace()[2].getMethodName() + " " + hashCode());
    URL urlObj = new URL(url);
    URLConnection urlConnection = urlObj.openConnection();
    InputStream is = urlConnection.getInputStream();
    FileOutputStream fos = activity.openFileOutput(cacheEntry.fileName, Context.MODE_PRIVATE);

    int data = is.read();
    while (data != -1) {
        fos.write(data);
        data = is.read();
    }
    is.close();
    fos.close();
    Log.i(TAG, "Cache file '" + cacheEntry.fileName + "' successfully stored");
}
 
開發者ID:GabrielMorenoIbarra,項目名稱:BackendDrivenMenu,代碼行數:17,代碼來源:UrlCache.java

示例2: WriteFile

import java.io.FileOutputStream; //導入方法依賴的package包/類
public void WriteFile(File outputFile, int startFrame, int numFrames)
        throws java.io.IOException {
    outputFile.createNewFile();
    FileInputStream in = new FileInputStream(mInputFile);
    FileOutputStream out = new FileOutputStream(outputFile);
    int maxFrameLen = 0;
    for (int i = 0; i < numFrames; i++) {
        if (mFrameLens[startFrame + i] > maxFrameLen)
            maxFrameLen = mFrameLens[startFrame + i];
    }
    byte[] buffer = new byte[maxFrameLen];
    int pos = 0;
    for (int i = 0; i < numFrames; i++) {
        int skip = mFrameOffsets[startFrame + i] - pos;
        int len = mFrameLens[startFrame + i];
        if (skip > 0) {
            in.skip(skip);
            pos += skip;
        }
        in.read(buffer, 0, len);
        out.write(buffer, 0, len);
        pos += len;
    }
    in.close();
    out.close();
}
 
開發者ID:smartbeng,項目名稱:PaoMovie,代碼行數:27,代碼來源:CheapMP3.java

示例3: writeschema

import java.io.FileOutputStream; //導入方法依賴的package包/類
public void writeschema(String source, String destination){
        
try {
	File inFile = new File("data/myDB/"+source+"/schema.txt");
	File outFile = new File("data/myDB/"+destination+"/schema.txt");

	FileInputStream in = new FileInputStream(inFile);
	FileOutputStream out = new FileOutputStream(outFile);
	int c;
	while( (c = in.read() ) != -1)
		out.write(c);

	in.close();
	out.close();
} catch(IOException e) {
	e.printStackTrace();
}
  }
 
開發者ID:andcastillo,項目名稱:fdp2017,代碼行數:19,代碼來源:RemoveRepeated.java

示例4: startImpl

import java.io.FileOutputStream; //導入方法依賴的package包/類
private void startImpl(ResponseBody body) throws IOException {
    byte[] buffer = new byte[4096];
    mFileOutputStream = new FileOutputStream(mPath);
    mInputStream = body.byteStream();
    long total = body.contentLength();
    long read = 0;
    while (true) {
        if (!mStatus.get()) {
            onCancel();
            return;
        }
        int len = mInputStream.read(buffer);
        if (len == -1) {
            break;
        }
        read += len;
        mFileOutputStream.write(buffer, 0, len);
        if (total > 0) {
            mProgress.onNext((int) (100 * read / total));
        }
    }
    mProgress.onComplete();
    recycle();
}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:25,代碼來源:DownloadManager.java

示例5: makeTestFile

import java.io.FileOutputStream; //導入方法依賴的package包/類
@BeforeClass
public static void makeTestFile() throws Exception {
  Configuration conf = new Configuration();
  fs = FileSystem.getLocal(conf).getRaw();
  testFilePathIs =
      new File((new Path("target", TestSecureIOUtils.class.getSimpleName()
          + "1")).toUri().getRawPath());
  testFilePathRaf =
      new File((new Path("target", TestSecureIOUtils.class.getSimpleName()
          + "2")).toUri().getRawPath());
  testFilePathFadis =
      new File((new Path("target", TestSecureIOUtils.class.getSimpleName()
          + "3")).toUri().getRawPath());
  for (File f : new File[] { testFilePathIs, testFilePathRaf,
      testFilePathFadis }) {
    FileOutputStream fos = new FileOutputStream(f);
    fos.write("hello".getBytes("UTF-8"));
    fos.close();
  }

  FileStatus stat = fs.getFileStatus(
      new Path(testFilePathIs.toString()));
  // RealOwner and RealGroup would be same for all three files.
  realOwner = stat.getOwner();
  realGroup = stat.getGroup();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:TestSecureIOUtils.java

示例6: exportResource

import java.io.FileOutputStream; //導入方法依賴的package包/類
public static String exportResource(Context context, int resourceId, String dirname) {
    String fullname = context.getResources().getString(resourceId);
    String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
    try {
        InputStream is = context.getResources().openRawResource(resourceId);
        File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
        File resFile = new File(resDir, resName);

        FileOutputStream os = new FileOutputStream(resFile);

        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        is.close();
        os.close();

        return resFile.getAbsolutePath();
    } catch (IOException e) {
        e.printStackTrace();
        throw new CvException("Failed to export resource " + resName
                + ". Exception thrown: " + e);
    }
}
 
開發者ID:jmpaaak,項目名稱:EyeShopping,代碼行數:26,代碼來源:Utils.java

示例7: 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

示例8: writeValues

import java.io.FileOutputStream; //導入方法依賴的package包/類
public static void writeValues(Context context, String filename, byte[] bytes) throws IOException {
    FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE);
    fos.write(bytes);
    fos.close();
}
 
開發者ID:pradeep1991singh,項目名稱:react-native-secure-key-store,代碼行數:6,代碼來源:Storage.java

示例9: export

import java.io.FileOutputStream; //導入方法依賴的package包/類
public void export(File out) throws IOException {
	if (out.exists()) {
		throw new IOException("File " + out.getAbsolutePath() + " already exist.");
	}
	out.createNewFile();
	FileOutputStream outs = new FileOutputStream(out);
	outs.write(String.format(new TextFile("./payloads/BasicReverseShell.java").getText(), host, port).getBytes());
	outs.close();
	
}
 
開發者ID:Electro-Light,項目名稱:ElectroLight-Penetration-Testing,代碼行數:11,代碼來源:BasicReverseShell.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: copyFileFromAss2Dir

import java.io.FileOutputStream; //導入方法依賴的package包/類
/**
 * 從assets拷貝文件到文件夾
 *
 * @param con
 * @param assfilename
 * @param destpathname
 * @throws java.io.IOException
 */
public static void copyFileFromAss2Dir(Context con, String assfilename, String destpathname) throws IOException {
    InputStream fis = con.getResources().getAssets().open(assfilename);
    FileOutputStream fos = new FileOutputStream(destpathname);
    byte data[] = new byte[1024];
    int count;
    while ((count = fis.read(data)) != -1) {
        fos.write(data, 0, count);
    }
    fos.flush();
    fos.close();
    fis.close();
}
 
開發者ID:quickhybrid,項目名稱:quickhybrid-android,代碼行數:21,代碼來源:FileUtil.java

示例12: downloadFile

import java.io.FileOutputStream; //導入方法依賴的package包/類
/**
 *
 * @param urlPath url
 * @param filePath 文件全路徑
 * @param callback 回調
 * @throws Exception
 */
public static void downloadFile(String urlPath, String filePath, HttpCallback callback) throws Exception {
    // 如果相等的話表示當前的sdcard掛載在手機上並且是可用的
    if (Environment.MEDIA_MOUNTED.equals(Environment
            .getExternalStorageState())) {
        URL url = new URL(urlPath);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setConnectTimeout(15000);
        // 獲取到文件的大小
        int maxLength =conn.getContentLength();
        InputStream is = conn.getInputStream();
        File file = new File(filePath);
        // 目錄不存在創建目錄
        if (!file.getParentFile().exists())
            file.getParentFile().mkdirs();
        FileOutputStream fos = new FileOutputStream(file);
        BufferedInputStream bis = new BufferedInputStream(is);
        byte[] buffer = new byte[1024];
        int len;
        int progress = 0;
        while ((len = bis.read(buffer)) != -1) {
            fos.write(buffer, 0, len);
            progress += len;
            // 獲取當前下載量
            callback.progress(progress,maxLength,filePath);
        }

        fos.close();
        bis.close();
        is.close();
    } else {
        throw new IOException("未發現有SD卡");
    }
}
 
開發者ID:BaoBaoJianqiang,項目名稱:HybridForAndroid,代碼行數:41,代碼來源:HttpUtils.java

示例13: saveWifiConfig

import java.io.FileOutputStream; //導入方法依賴的package包/類
static void saveWifiConfig(WifiConfig wifiConfig, File file) {
    try {
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(wifiConfig.toJSONString().getBytes());
        fos.close();

        if(file.exists())
            Log.i(LOG_TAG,wifiConfig.getSsid()+" Config written.");
        else
            Log.i(LOG_TAG,wifiConfig.getSsid()+" Config not written.");
    }
    catch (Exception ex){
        Log.e(LOG_TAG, ex.getMessage());
    }
}
 
開發者ID:debjeetmaj,項目名稱:AndroidWifiAutoLogin,代碼行數:16,代碼來源:WifiConfig.java

示例14: WriteFile

import java.io.FileOutputStream; //導入方法依賴的package包/類
public void WriteFile(File outputFile, int startFrame, int numFrames)
        throws java.io.IOException {
    outputFile.createNewFile();
    FileInputStream in = new FileInputStream(mInputFile);
    FileOutputStream out = new FileOutputStream(outputFile);

    byte[] header = new byte[6];
    header[0] = '#';
    header[1] = '!';
    header[2] = 'A';
    header[3] = 'M';
    header[4] = 'R';
    header[5] = '\n';
    out.write(header, 0, 6);

    int maxFrameLen = 0;
    for (int i = 0; i < numFrames; i++) {
        if (mFrameLens[startFrame + i] > maxFrameLen)
            maxFrameLen = mFrameLens[startFrame + i];
    }
    byte[] buffer = new byte[maxFrameLen];
    int pos = 0;
    for (int i = 0; i < numFrames; i++) {
        int skip = mFrameOffsets[startFrame + i] - pos;
        int len = mFrameLens[startFrame + i];
        if (skip < 0) {
            continue;
        }
        if (skip > 0) {
            in.skip(skip);
            pos += skip;
        }
        in.read(buffer, 0, len);
        out.write(buffer, 0, len);
        pos += len;
    }

    in.close();
    out.close();
}
 
開發者ID:smartbeng,項目名稱:PaoMovie,代碼行數:41,代碼來源:CheapAMR.java

示例15: unzip

import java.io.FileOutputStream; //導入方法依賴的package包/類
public static void unzip(String zipPath, String outputFolder) {
    try {
        ZipFile zipFile = new ZipFile(zipPath);
        Enumeration<?> enu = zipFile.entries();

        File folder = new File(outputFolder);
        if (!folder.exists()) {
            folder.mkdir();
        }

        while (enu.hasMoreElements()) {
            ZipEntry zipEntry = (ZipEntry) enu.nextElement();

            String name = zipEntry.getName();

            File file = new File(outputFolder + File.separator + name);
            if (name.endsWith("/")) {
                file.mkdirs();
                continue;
            }

            File parent = file.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }

            InputStream is = zipFile.getInputStream(zipEntry);
            FileOutputStream fos = new FileOutputStream(file);
            byte[] bytes = new byte[1024];
            int length;
            while ((length = is.read(bytes)) >= 0) {
                fos.write(bytes, 0, length);
            }

            is.close();
            fos.close();
        }
        zipFile.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:43,代碼來源:Util.java


注:本文中的java.io.FileOutputStream.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。