Reputation:
Hi am trying to download a file from the Firebase Storage in to the cache. That works fine. My Problem is that I can't change the entire filename. I can only change the prefix and the suffix. This is the filename that I am getting.
System.out: myImage -1452943744jpg
How can I remove the numbers and just change the filename to myImage?
This is my code:
try {
localFile = File.createTempFile( "myImage " ,"jpg");
System.out.println(localFile.getName());
} catch (IOException e) {
e.printStackTrace();
}
liftImage.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
// Local temp file has been created
myBitmap = BitmapFactory.decodeFile(localFile.getAbsolutePath());
myImageView.setImageBitmap(myBitmap);
}
Upvotes: 3
Views: 1605
Reputation: 38289
When you request the system to create a temporary file, it generates a unique file name using the prefix and suffix you provide and a string that makes the name unique. In this case the string is the number field you observe, probably derived from the current system time. If you want complete control over the file name, you cannot use createTempFile()
.
Instead, decide where you want the file to be located and create the file like this:
localFile = new File(XXXX, "myImage.jpg");
where XXXX is one of methods of Context
that returns a directory:
This guide describes some of the considerations for using cache, internal and external file storage.
Upvotes: 3