当前位置: 首页>>代码示例>>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;未经允许,请勿转载。