Assets 파일 내용을 지정된 폴더로 복사
3335 단어 assets
package com.handler;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.content.res.AssetManager;
public class DuplicateHandler {
private static DuplicateHandler mDuplicateHandler;
private AssetManager mAssetManager = null;
public static DuplicateHandler getInstance(Client mClient) {
if (mDuplicateHandler == null) {
mDuplicateHandler = new DuplicateHandler(mClient);
}
return mDuplicateHandler;
}
public DuplicateHandler(Client mClient) {
this.mClient = mClient;
}
private String[] getImages(String mDirectory) {
String[] tempImages = null;
try {
mAssetManager = mClient.getAssets();
if (null != mAssetManager) {
tempImages = mAssetManager.list(mDirectory);
}
} catch (IOException e) {
e.printStackTrace();
}
return tempImages;
}
public void initPath(String mDirName) {
try {
//
String mLastPath = Common.mCachePath + "/" + mDirName;
File mLastFolder = new File(mLastPath);
if (!mLastFolder.exists()) {
mLastFolder.mkdirs();
}
mLastFolder = null;
} catch (Exception e) {
e.printStackTrace();
}
}
/** Assets . */
public boolean duplicateImages(String mPath) {
initPath(mPath);
String[] mAllImages = getImages(mPath);
InputStream mFileIn = null;
FileOutputStream mFileOut;
File mFile;
for (int i = 0; i < mAllImages.length; i++) {
if (!mAllImages[i].endsWith(".png")
&& !mAllImages[i].endsWith(".jpg")
&& !mAllImages[i].endsWith(".gif")
&& !mAllImages[i].endsWith(".html")
) {
duplicateImages(mPath + "/" + mAllImages[i]);
} else {
try {
mFile = new File(Common.mCachePath + "/" + mPath + "/"
+ mAllImages[i]);
if (!mFile.exists()) {
mFile.createNewFile();
}
mFileIn = mAssetManager.open(mPath + "/" + mAllImages[i]);
mFileOut = new FileOutputStream(mFile);
int readedBytes;
byte[] buf = new byte[128];
while ((readedBytes = mFileIn.read(buf)) > 0) {
mFileOut.write(buf, 0, readedBytes);
}
mFileOut.flush();
mFileOut.close();
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}
return true;
// BitmapDrawable bitmapDrawable = (BitmapDrawable) image.getDrawable();
// if (bitmapDrawable != null &&
// !bitmapDrawable.getBitmap().isRecycled()) {
// bitmapDrawable.getBitmap().recycle();
// }
// image.setImageBitmap(BitmapFactory.decodeStream(assetFile));
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Assets.xcassets의 이미지 사이즈 일람표최근 Xcode 9.xcode를 사용하기 시작했지만 여전히 Xcode의 Asseets입니다.xcassets에 필요한 이미지 사이즈 일람표에는 보기 쉬운 것이 보이지 않기 때문에 직접 만들어 봤습니다. 차트의 표시 순...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.