- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将文件“LICENSE.txt”从我的 PC 上传到 Android WebServerApp。NanoHTTPD 使用一个临时目录来保存上传的文件。临时位置由以下决定:
tmpdir = System.getProperty("java.io.tmpdir");
文件上传为:/data/data/com.manmohan.mynanoserver/cache/NanoHTTPD-1736025823 在我的例子中。
上传后我想将文件移动到我的 SD 卡“/storage/extSdCard/Uploads”。
这是我的做法:
String tempFileName = entry.getValue().toString();
File fileToMove = new File(tempFileName); // temp file path returned by NanoHTTPD
String p = "/storage/extSdCard/Uploads";
String newFile = p + "/LICENSE.txt";
File nf = new File(newFile); // I want to move file here
if (fileToMove.canWrite()) {
boolean success = fileToMove.renameTo(nf);
if (success == true) {
// LOG to console
Log.i("FILE_MOVED_TO", newFile);
} else {
Log.e("FILE_MOVE_ERROR", tempFileName);
}
} else {
Log.e("PERMISSION_ERROR_TEMP_FILE", tempFileName);
}
我无法访问 /data/。 . . 目录和其中的文件,尝试移动文件时出错。
但是这个临时路径有效:
tmpdir = "/storage/extSdCard/temp-uploads-nanohttpd";
java.io.tmpdir 有什么问题?如果 NanoHTTPD 可以写入,那为什么我不能移动文件?
最佳答案
由于源和目标位于不同的文件系统上,因此无法进行简单的重命名。 renameTo
方法的文档指出:
Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.
要解决此问题,请将文件复制到新位置并将其从旧位置删除。
关于android - 将从 nanohttpd 的临时目录上传的文件移动到 SD 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20869506/
在我的代码中,我想以编程方式选择一些变量,并以硬编码方式选择和重命名其他一些变量。我知道我可以通过 setnames() 分两步实现这一点。 ,但我很好奇如何一步完成。 我想我很接近它通过 .SDco
(添加了可重现的示例。) 我对 rnorm 函数有点困惑。 我期待 mean(rnorm(100,mean=0,sd=1))为0;和 sd(rnorm(100,mean=0,sd=1))为 1。但给出
我想创建一个包含多个不同列的数据框,其中包含平均值,之后 sd 显示在括号中。举个例子: df % group_by(Species) %>% summarise_all(list(~ s
我很想知道 SD 卡是否提供类似于“SMART”信息的内容,例如硬盘和 SSD。 我有兴趣在 Raspberry PI 中检查 SD 卡的健康信息,以进行预防性更换。我的写入需求非常高,对设备的物理访
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
是否可以通过编程将 sd 卡中存在的文件夹复制到存在同一 sd 卡的另一个文件夹?? 如果是这样,该怎么做? 最佳答案 该示例的改进版本: // If targetLocation does not
Link :I worked on based on this Link 我添加了这一行来查找尺寸(内部和外部)尺寸, return availableExternalMemorySize/(1024
我正在开发一个应用程序,其中我需要从 sd 卡 中选择一个图像并在 ImageView 中显示它。现在我希望用户通过单击一个按钮来减小/增加其宽度,然后将其保存回 sd 卡。 我已经完成了图像挑选并在
在我的应用程序中,我使用以下 Intent 获得了 SD 卡写入权限。如果用户从系统文件资源管理器中选择 sd 卡文件夹,那么我就有 sd 卡写权限。 Intent intent = new Inte
给定一个data.table library(data.table) DT = data.table(x=rep(c("b","a","c"),each=3), v=c(1,1,1,2,2,1,1,2
我正在构建一个程序,该程序对 pin0 上的模拟电压进行 10 次测量,并将其打印到日志文件中。当我尝试确保文件为空时,我遇到了这个问题。我正在使用 SD.remove() 来删除以前的日志文件。当我
在 Android 的 API > 19 中是否有任何方法可以获取可移动 SD 卡的路径? 与外部 SD 卡一样,我们有 Environment.getExternalStorageDirectory
我使用以下方法检查手机是否包含 SD 卡,但如果 SD 卡不可用,问题总是返回 true,请帮助我。 Boolean isSDPresent = android.os.Environment.getE
这是我将 512 字节块写入 SD 卡的代码。代码工作正常,但是当我检查一切正常时(通过阅读 SD 的响应),我读到 0xFF . 该值应该类似于(来自 SD 引用手册): ‘010’—Data ac
我有两个线程在 epoll 上运行。一个线程尝试与服务器建立 TCP 连接,使用 EPOLL_CTL_ADD 选项将套接字添加到 epoll-fd。 另一个线程负责等待添加到 epoll-fd 的 S
我正在使用 eclipse 模拟器,我想以编程方式将一些 mp3 从 /sdcard/songs 复制到 /sdcard/backup,有什么办法吗?非常感谢任何帮助和代码 fragment !谢谢!
我正在使用 Docker Desktop for Mac 版本 2.1.0.4。我有一个 Docker 容器,它是一个 Ubuntu 18.04 Linux VM,里面有 Yocto Build 系统
好的,这个黑莓应用程序在第一次安装和运行时创建了一个数据库。它安装在 SD 卡上。 当我删除应用程序时 - 这个文件仍然存在,我在删除应用程序时找不到任何删除它的方法。 有什么建议么? 最佳答案 应用
我有一张 SD 卡(或 SDHC 卡)通过 SPI 模式连接到微 Controller 。我正在使用 Chan’s FAT图书馆。我将来自 8192 字节缓冲区的数据写入其中(由于 RAM 不足,缓冲
我想在删除该选择中的最小值和最大值后,计算数据框中每一行在该选择列上的标准差。这是一个例子: set.seed(1) dat dat X1 X2 X3 X4 X5 sd 1 27 5
我是一名优秀的程序员,十分优秀!