本文整理汇总了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");
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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);
}
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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卡");
}
}
示例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());
}
}
示例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();
}
示例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();
}
}