Q
Q
qqweer2020-07-20 23:30:04
Android
qqweer, 2020-07-20 23:30:04

How to swap the contents of files?

In general, I have 2 fields EditText(id - filepath, filepath2), button(id-perform). You need to swap the contents of the files. The bottom line is that when you enter the correct path to the objects, they exchange values, otherwise "error" is displayed. If there are any errors in the code, I will be glad to hear. Thanks in advance!
perform.setOnClickListener {
val path1 = File(
Environment.getExternalStorageDirectory(),
"$filepath")
val path2 = File(
Environment.getExternalStorageDirectory(),
"$filepath2")
val fileExists1 = path1.exists()
val fileExists2 = path2.
}
else filepath.setText("error", TextView.BufferType.EDITABLE)
if(fileExists2) {
}
else filepath2.setText("error", TextView.BufferType.EDITABLE)
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maaGames, 2020-07-21
@maaGames

file1 -> move to -> temp_file_name
file2 -> move to -> file1
temp_file_name -> move to file1
i.e. there is no need to change the "content", you can simply rename / move the files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question