i display all the images, videos and audio files from external storage in my app but when i try to rename it does not work
i am using renameTo method to rename a file but it does not work for android 10 and above. Below code works for android older versions only
how can i rename file in android 10 and above versions
val from: File = File(currentMusic!!.path!!)
val mBaseFolderPath: String =getpath()
val str = renameBinding.renameEd.text
val to: File = File(mBaseFolderPath, "$str.mp3")
from.renameTo(to)
Related
I'm using below code to list out files in nested folder
val hdfspath="/data/retail/apps/*/landing"
import org.apache.hadoop.fs. (FileSystem, Path) val fs= org.apache.hadoop.fs.FileSystem.get (spark.sparkContext.hadoopConfiguration) fs.listStatus (new Path (s"S(hdfspath)")).filter(.isDirectory).map(_.getPath).foreach (printin)
If I use path as below
hdfspath="/data/retail/apps"
getting results but if I use val hdfspath="/data/retail/apps/*/landing" then I'm getting error it's showing path not exist error.plese help me out.
Error Image
according to this answer, you need to use globStauts instead of listStatus:
fs.globStatus(new Path (s"S(hdfspath)")).filter(.isDirectory).map(_.getPath).foreach (println)
I have a maven project with a category.txt file in src/main/resources.
I have a simple job:
package com.test.utilityjobs
import scala.io.Source
object CategoriesLoadingTestJob {
def main(args: Array[String]): Unit = {
val categoryListSource = Source.fromInputStream(getClass.getResourceAsStream("/categories.txt"))
categoryListSource.getLines().toList.foreach(println)
}
}
Which works fine if launched on my local machine or in emr 5.*
However, in emr 6.3, whenever I launch this simple job, I get this error:
java.nio.charset.MalformedInputException: Input length = 1
I've also tried
val categoryListSource: BufferedSource = Source.fromResource("cat2.txt")
but this gives me the same error.
I've checked the file encoding, it is UTF-8. The compiler encoding is UTF-8. I've tried with other files and everything works fine
It is possible to specify the encoding while reading a property file in scala, so I tried
val categoryListSource = Source.fromInputStream(getClass.getResourceAsStream("/categories.txt"))("UTF-8")
and it worked. It still complains about files with BOM so I removed the BOM from the existing file.
I want to get details about a selected harbour,by taking val s from a list extracted using readLines from a .txt file, where each harbour has a .txt file in the assets directory. I generate the file name but when the app is run in the emulator I get a file not found error.
In this case I am trying to get at a file called Brehatharm.txt
var portChosen = "Brehat"
//"tide2a/app/src/main/assets/"+//various paths to try
fileName = "assets/"+portChosen+"harm.txt"
val harmConsList:List<String> = File(fileName).readLines()
val portDisplayName = harmConsList[0]
val longTude = harmConsList[1]
val MTL =harmConsList[2]
etc,
The log cat reads :-
2021-01-10 15:40:34.044 7108-7108/com.example.tide2a E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tide2a, PID: 7108
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tide2a/com.example.tide2a.MainActivity}: java.io.FileNotFoundException: assets/Brehatharm.txt: open failed: ENOENT (No such file or directory)
The full windows path to the file is :-
C:\Users.......\OneDrive\Coding projects\tide2a\app\src\main\assets\Brehatharm.txt
I am sure the file is there, and spelled correctly, so I suspect I am specifying the path incorrectly. Please advise me.
Files in assets/ cannot be accessed using the File class. Use context.assets to get the AssetManager, and you can open InputStreams to the files.
i am trying to pass uri as
File file = new File(Environment.getExternalStorageDirectory(), "/c4611_sample_explain.pdf");
Log.e( "error" ,file.toURI().toString());/in logcat E/error:file:/storage/emulated/0/c4611_sample_explain.pdf/
.uri (file.toURI().toString())
.name("c4611_sample_explain.pdf")
in build method of docusign android sdk however its giving me error
11121-11121/com.example.docusignapp E/main: Unknown exception in loading document: File not found at specified URI.
tried
.uri("file:///storage/emulated/0/c4611_sample_explain.pdf")
.name("c4611_sample_explain.pdf")
also tried
.uri("file:///storage/emulated/0")
.name("c4611_sample_explain.pdf")
In android phone file is in path /storage/emulated/0/downloads
kindly help
Can you try the following:
File file = new File(Environment.getExternalStorageDirectory(), "/c4611_sample_explain.pdf");
URI fileURI = file.toURI();
Then,
.uri(fileURI.toString());
I need to use a xml file in my code,
in Java it looks like this:
File inputFile = new File("test.xml"); //Path: C:\Users\...
however, when i try the same in kotlin, it does not work:
val inputFile = File("test.xml")
I always get an "File not found" exception.
I can't find anything on google on how to include files with Kotlin.
val inputStream: InputStream = File("test.xml").inputStream()
val inputString = inputStream.bufferedReader().use { it.readText() }
println(inputString)
Source : kotlination.com
The file must be in the root of your project, the same folder containing your src/ folder.
These should give the exact same results, if you run both with the same working directory. You can check or set the working directory (relative to which file.xml will be looked for) in the Run/Debug configuration.
Since you have Android Studio tag: if you are creating an Android application/library and want the file to be included with it, you should read https://developer.android.com/guide/topics/resources/index.html.