Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将当前时间存储到外部存储器?_Java_Android - Fatal编程技术网

Java 如何将当前时间存储到外部存储器?

Java 如何将当前时间存储到外部存储器?,java,android,Java,Android,我编写了一个函数来获取当前时间 在另一个函数中调用此函数时,我在Logcat中获取当前时间。有谁能帮我把它存储在android studio的外部存储器中吗 注:我已补充 在manifest.xml中 try { File file = new File(Environment.getExternalStorageDirectory(), "time.txt"); FileWriter fw = new FileWriter(file);

我编写了一个函数来获取当前时间

在另一个函数中调用此函数时,我在Logcat中获取当前时间。有谁能帮我把它存储在android studio的外部存储器中吗

注:我已补充 在manifest.xml中

try {
            File file = new File(Environment.getExternalStorageDirectory(), "time.txt");
            FileWriter fw = new FileWriter(file);
            PrintWriter pw = new PrintWriter(fw);
            String currentTime = "";//call here your method which gives you current time
            pw.println(currentTime);
            pw.close();
            fw.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

别忘了添加权限

可能的副本,请检查保存数据的官方文档:对于标准格式文本的当前时刻,请使用:
Instant.now().toString()
➙ <代码>2018-10-06T23:22:09.827625Z。对于早期的Android,请参阅ThreeTen Backport和ThreeTenABP项目。