Commit 857ecea7 authored by fallenstardust's avatar fallenstardust

copyFile

parent 215be7b2
...@@ -121,6 +121,7 @@ public interface Constants { ...@@ -121,6 +121,7 @@ public interface Constants {
int UNSORT_TIMES = 0x80; int UNSORT_TIMES = 0x80;
int CARD_RESULT_GRAVITY = Gravity.LEFT;
int CARD_SEARCH_GRAVITY = Gravity.RIGHT; int CARD_SEARCH_GRAVITY = Gravity.RIGHT;
int STRING_LIMIT_START = 1315; int STRING_LIMIT_START = 1315;
int STRING_CATEGORY_START = 1100; int STRING_CATEGORY_START = 1100;
...@@ -199,4 +200,7 @@ public interface Constants { ...@@ -199,4 +200,7 @@ public interface Constants {
//额外的cdb //额外的cdb
boolean NETWORK_IMAGE = false; boolean NETWORK_IMAGE = false;
boolean SHOW_MYCARD = !"core".equals(BuildConfig.FLAVOR); boolean SHOW_MYCARD = !"core".equals(BuildConfig.FLAVOR);
//打开ydk,是否复制到文件夹
boolean COPY_YDK_FILE = false;
} }
...@@ -160,25 +160,25 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa ...@@ -160,25 +160,25 @@ public abstract class BaseCardsAcitivity extends BaseActivity implements CardLoa
protected abstract void onCardLongClick(View view, Card cardInfo, int pos); protected abstract void onCardLongClick(View view, Card cardInfo, int pos);
protected void showSearch(boolean autoclose) { protected void showSearch(boolean autoClose) {
if (mDrawerlayout.isDrawerOpen(Gravity.LEFT)) { if (mDrawerlayout.isDrawerOpen(Constants.CARD_RESULT_GRAVITY)) {
mDrawerlayout.closeDrawer(Gravity.LEFT); mDrawerlayout.closeDrawer(Constants.CARD_RESULT_GRAVITY);
} }
if (autoclose && mDrawerlayout.isDrawerOpen(Constants.CARD_SEARCH_GRAVITY)) { if (autoClose && mDrawerlayout.isDrawerOpen(Constants.CARD_SEARCH_GRAVITY)) {
mDrawerlayout.closeDrawer(Constants.CARD_SEARCH_GRAVITY); mDrawerlayout.closeDrawer(Constants.CARD_SEARCH_GRAVITY);
} else if (isLoad) { } else if (isLoad) {
mDrawerlayout.openDrawer(Constants.CARD_SEARCH_GRAVITY); mDrawerlayout.openDrawer(Constants.CARD_SEARCH_GRAVITY);
} }
} }
protected void showResult(boolean autoclose) { protected void showResult(boolean autoClose) {
if (mDrawerlayout.isDrawerOpen(Constants.CARD_SEARCH_GRAVITY)) { if (mDrawerlayout.isDrawerOpen(Constants.CARD_SEARCH_GRAVITY)) {
mDrawerlayout.closeDrawer(Constants.CARD_SEARCH_GRAVITY); mDrawerlayout.closeDrawer(Constants.CARD_SEARCH_GRAVITY);
} }
if (autoclose && mDrawerlayout.isDrawerOpen(Gravity.LEFT)) { if (autoClose && mDrawerlayout.isDrawerOpen(Constants.CARD_RESULT_GRAVITY)) {
mDrawerlayout.closeDrawer(Gravity.LEFT); mDrawerlayout.closeDrawer(Constants.CARD_RESULT_GRAVITY);
} else if (isLoad) { } else if (isLoad) {
mDrawerlayout.openDrawer(Gravity.LEFT); mDrawerlayout.openDrawer(Constants.CARD_RESULT_GRAVITY);
} }
} }
} }
...@@ -4,13 +4,27 @@ import java.io.BufferedReader; ...@@ -4,13 +4,27 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class FileUtils { public class FileUtils {
public static boolean deleteFile(File file){
if(file.isFile()){
try {
file.delete();
}catch (Throwable e){
return false;
}
}
return true;
}
public static List<String> readLines(String file, String encoding) { public static List<String> readLines(String file, String encoding) {
InputStreamReader in = null; InputStreamReader in = null;
FileInputStream inputStream = null; FileInputStream inputStream = null;
...@@ -64,20 +78,47 @@ public class FileUtils { ...@@ -64,20 +78,47 @@ public class FileUtils {
return true; return true;
} }
public static void copyFile(String in, FileOutputStream outputStream) { public static void copyFile(InputStream in, File out) {
FileOutputStream outputStream = null;
try {
File dir = out.getParentFile();
if(!dir.exists()){
dir.mkdirs();
}
outputStream = new FileOutputStream(out);
copy(in, outputStream);
} catch (Throwable e) {
e.printStackTrace();
}finally {
IOUtils.close(outputStream);
IOUtils.close(in);
}
}
public static void copyFile(File in, File out) {
FileOutputStream outputStream = null;
FileInputStream inputStream = null; FileInputStream inputStream = null;
byte[] data = new byte[1024 * 8];
try { try {
inputStream = new FileInputStream(in); File dir = out.getParentFile();
int len; if(!dir.exists()){
while ((len = inputStream.read(data)) != -1) { dir.mkdirs();
outputStream.write(data, 0, len);
} }
inputStream = new FileInputStream(in);
outputStream = new FileOutputStream(out);
copy(inputStream, outputStream);
} catch (Throwable e) { } catch (Throwable e) {
// e.printStackTrace();
} finally { }finally {
IOUtils.close(outputStream); IOUtils.close(outputStream);
IOUtils.close(inputStream); IOUtils.close(inputStream);
} }
} }
public static void copy(InputStream in, OutputStream out) throws IOException {
byte[] data = new byte[1024 * 8];
int len;
while ((len = in.read(data)) != -1) {
out.write(data, 0, len);
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment