gpt4 book ai didi

android - 将视频文件保存到 sd 卡文件夹

转载 作者:行者123 更新时间:2023-11-30 04:36:37 27 4
gpt4 key购买 nike

我想将视频文件存储到 SD 卡中我的应用程序文件夹中。目前我正在拍摄视频并且我有它的 URI。我怎样才能保存那个文件?请回复。提前致谢。

最佳答案

static void writeData(String fileurl, boolean append, String path,
String filename, Activity mContext) throws CustomException
{
URL myfileurl = null;
ByteArrayBuffer baf = null;
HttpURLConnection conn = null;
final int length;
try {
myfileurl = new URL(fileurl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
conn = (HttpURLConnection) myfileurl
.openConnection();
conn.setDoInput(true);
conn.connect();
conn.setConnectTimeout(100000);

length = conn.getContentLength();
System.out.println("total length.." + length);

int interval = (int)length/100;
if (length > 0) {
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
baf = new ByteArrayBuffer(1000);
int current = 0;

while ((current = bis.read()) != -1) {
try {
baf.append((byte) current);
mBufferError=false;
} catch (Exception e){
// TODO: handle exception
mBufferError=true;
System.out.println("buffer Problem");
e.printStackTrace();
throw new CustomException("@@@ memory problem ", "Buffer Error");
}
}
}

} catch (IOException e) {
mBufferError=true;
System.out.println("HttpURLConnection");
e.printStackTrace();

}
try{
if(conn.getResponseCode()==200 && mBufferError==false)
{
path = path + "/" + filename;
boolean appendData = append;
FileOutputStream foutstream;

File file = new File(path);
boolean exist = false;

try {
if (appendData)
exist = file.exists();
else
exist = file.createNewFile();
} catch (IOException e) {
try {
System.out.println("@@@ existed file :" + path);
return;
} catch (Exception err) {
Log.e("SAX", err.toString());
}
}
if (!appendData && !exist) {
} else if (appendData && !exist) {

} else {
try {
foutstream = new FileOutputStream(file, appendData);
foutstream.write(baf.toByteArray());
foutstream.close();
} catch (Exception e) {
System.out.println("error in closing! " + e);
e.printStackTrace();
}
}
}
}catch (Exception e) {
// TODO: handle exception
throw new CustomException("@@@ I/O problem ", "I/O Error");
}
}

可以使用,其中 fileurl= 您的 Url 和 path= 本地存储路径

关于android - 将视频文件保存到 sd 卡文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6728651/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com