mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-16 10:56:50 -04:00
Merge pull request #2305 from gouri-panda/filereader_java_file_to_kotlin
Convert FileReader.java file to kotlin #2306
This commit is contained in:
commit
a5f3e74c83
@ -15,31 +15,18 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.kiwix.kiwixmobile.core.main;
|
package org.kiwix.kiwixmobile.core.main
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader
|
||||||
import java.io.InputStream;
|
import java.io.IOException
|
||||||
import java.io.InputStreamReader;
|
|
||||||
|
|
||||||
public class FileReader {
|
class FileReader {
|
||||||
|
fun readFile(filePath: String?, context: Context): String = try {
|
||||||
public String readFile(String filePath, Context context) {
|
context.assets.open(filePath)
|
||||||
try {
|
.bufferedReader()
|
||||||
StringBuilder buf = new StringBuilder();
|
.use(BufferedReader::readText)
|
||||||
InputStream json = context.getAssets().open(filePath);
|
} catch (e: IOException) {
|
||||||
BufferedReader in =
|
"".also { e.printStackTrace() }
|
||||||
new BufferedReader(new InputStreamReader(json, "UTF-8"));
|
|
||||||
String str;
|
|
||||||
|
|
||||||
while ((str = in.readLine()) != null) {
|
|
||||||
buf.append(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
in.close();
|
|
||||||
return buf.toString();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user