java拷貝資料夾和android設定檔案許可權
拷貝資料夾的程式碼:
public boolean copy(String file1,String file2) {
File in=new File(file1);
File out=new File(file2);
if(!in.exists()){
return false;
}
else {
}
if(!out.exists())
out.mkdirs();
File[] file=in.listFiles();
FileInputStream fin=null;
FileOutputStream fout=null;
for(int i=0;i<file.length;i++){
if(file[i].isFile()){
try {
fin=new FileInputStream(file[i]);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
File f = new File(file2+"/"+file[i].getName());
fout=new FileOutputStream(f);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int c;
byte[] b=new byte[1024*5];
try {
while((c=fin.read(b))!=-1){
fout.write(b, 0, c);
}
fin.close();
fout.flush();
fout.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// return true;
}
else copy(file1+"/"+file[i].getName(),file2+"/"+file[i].getName());
}
return false;
}
android上設定資料夾許可權有兩種方法
1:
try {
String command = "chmod 644 " + f.getAbsolutePath();
Runtime runtime = Runtime.getRuntime();
java.lang.Process proc = runtime.exec(command);
} catch (IOException e) {
e.printStackTrace();
}
2:
使用FileUtils,這個類預設是隱藏的,官方sdk中不包含這個類,所以程式碼如果要使用這個類,需要將工程放到android原始碼中編譯
FileUtils.setPermissions(f.getAbsolutePath(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IROTH, -1, -1) ;
相關推薦
java拷貝資料夾和android設定檔案許可權
拷貝資料夾的程式碼: public boolean copy(String file1,String file2) { File in=new File(file1); File out=new
Java刪除資料夾和其子檔案、檔案的拷貝和剪下
1、遞迴刪除目錄下的所有檔案及子目錄下所有檔案 //遞迴刪除目錄下的所有檔案及子目錄下所有檔案 public static boolean deleteDir(File dir) { if (dir.isDirectory()) {
Outlook新建資料檔案拷貝資料夾和規則的巨集
outlook資料檔案變大後會新建一個數據檔案,但如果之前建立了大量規則,那麼新建和修改這些檔案和規則會是件讓人頭痛的事 經過一天的摸索,完成了資料夾的複製,規則的目標資料夾的替換,以下是程式碼 Sub testMacro() Dim defaultStore As Sto
java壓縮資料夾和檔案例項
package com.cn;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.i
百度——個人雲端儲存pcs——Android使用百度雲盤(2)——建立資料夾和上傳檔案
經過驗證,直接使用access_token即可。不用再重新申請了。 遇到的一些小問題: 1.資料夾可以建立多級,比如A/B/C,可以一起建立 2.如果建立失敗,有可能是資料夾命名問題。沒有找到規律。但是好像叫tlist就不行。 3.上傳檔案,比較慢。上傳一般都啟動後臺執行緒
java將資料夾下的一個檔案拷貝到另一個資料夾下
public static void copy(String file1, String file2) {System.out.println(file1);System.out.println(file2);File src=new File(file1);File ds
遍歷資料夾和遍歷檔案
void FileTraverse(String m_FileDir,StringVector& vFilePath) {//遍歷時子目錄為檔案 String pattern = m_FileDir+ _T("\\*.*");//所有檔案都列出 FileFind fin
Java 讀取資料夾檢查是否新增檔案 檔案監聽器
建立一個檔案監聽器 監聽資料夾下檔案的變化 使用 commons-io 中的檔案監控 import java.util.concurrent.TimeUnit; import org.apache.commons.io.filefilter.FileFilterU
MFC 利用CFileDialog讀取資料夾和多個檔案
專案1、彈出選擇視窗,選擇並獲得了多個檔案的檔名(不含路徑) void CMFrame::OnBnClickedDlginput() { // TODO: 在此新增控制元件通知處理程式程式碼 CFileDialog dlg( TRUE, NULL, NULL,
【加快cocos2d-x編譯速度】cocos2d-x編譯專案時避免拷貝資料夾和庫
http://codingnow.cn/cocos2d-x/928.html 本文參考自子龍山人的部落格,跟他的方法也有少許的不同,自己用著舒心才是最重要的。cocos2d-x的版本更新太快了,本文使用的是最新的cocos2d-x 2.0.4版本,IDE是vs2010
Java-拷貝資料夾
用Java程式碼編寫一個實現拷貝資料夾的功能 思路: 1、先在目的路徑建立一個與要被拷貝資料夾名相同名字的資料夾 2、將原資料夾中的所有成員(包括子資料夾以及檔案)遍歷一遍,並同時判斷每一個成員是否為檔案;是檔案則複製檔案到指定的目的路徑中;如不是,則此成
Python遍歷資料夾和讀寫檔案的方法
#-*- coding: UTF-8 -*- ''' 1、讀取指定目錄下的所有檔案 2、讀取指定檔案,輸出檔案內容 3、建立一個檔案並儲存到指定目錄 ''' import os # 遍歷指定目錄,顯示目錄下的所有檔名 def eachFile(filepath): pathDir = os.l
java 合併資料夾下多個檔案
package test.com.whty.platform.modules.interfaces; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; im
Java刪除資料夾及資料夾下的子資料夾和子檔案
Java刪除資料夾及資料夾下的子資料夾和子檔案 public class Test { public static void main(String[] args){ File file = new File("D:\\a"); delAllFile(f
VS2012、VS2013環境將ipch資料夾和sdf檔案移除到其他地方的設定以減小工程大小
在使用Visual Studio 2010開發C++程式的時候,會發現有一些奇怪的檔案被創建出來,比如一個叫ipch的資料夾,和一個與工程同名的.sdf檔案,而且ipch下面的檔案和.sdf檔案都很大,至少有10M,大專案可能超過100M,那這些檔案是幹什麼用的呢? 這些檔
java 同時建立多個資料夾和檔案
public void demo1() { try { File dir = new File("d:\\abc\\bcd"); if (!dir.exists()) { dir.mkdirs(); } File file = new
JAVA如何建立資料夾和檔案並可以追加寫入txt
public static void createFile(String filePath1,String fileName,StringBuffer stringBuffer) throws IOException { Stri
【Android】專案中資料夾和檔案的作用
Table of Contents 資料夾的作用 檔案的作用 資料夾的作用 No. 資料夾 描述 1 src 存放
Android中建立資料夾和檔案的操作
本文重溫講解下Android中如何建立資料夾和檔案, 1、首先需要新增許可權 <span style="font-size:10px;"><!--在sdcard中新增寫入資料的許可權 --> <uses-permission a
JAVA android 獲取assets資料夾中的properties檔案 並從中獲取資料
class PropertiesUtils { private static Properties properties = null; private static void readProperties() { try {