2024年Android最新Android 读取本地txt文件和写入txt文件到本地,2024年最新android高级面试题2024

总结

最后为了帮助大家深刻理解Android相关知识点的原理以及面试相关知识,这里放上相关的我搜集整理的14套腾讯、字节跳动、阿里、百度等2021最新面试真题解析,我把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包知识脉络 + 诸多细节。

2020面试真题解析
腾讯面试真题解析

阿里巴巴面试真题解析

字节跳动面试真题解析
网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

*/

public static boolean saveDeviceId(String deviceId) {

File file = new File(Constant.PATH_SAVE_DEVICE + fileName);

if (file.exists()) {

FileUtil.delete(Constant.PATH_SAVE_DEVICE + fileName);

}

return writeTxtToFile(Base64Util.encode(deviceId), Constant.PATH_SAVE_DEVICE, fileName);//对保存的设备ID加密保存

}

/**

  • 保存收费标准

  • @param rate 输入的收费标准

*/

public static boolean saveRate(String rate) {

File file = new File(Constant.PATH_RATE + rateName);

if (file.exists()) {

FileUtil.delete(Constant.PATH_RATE + rateName);

}

return writeTxtToFile(rate, Constant.PATH_RATE, rateName);//对保存的收费标准

}

/**

  • 字符串写入本地txt

  • @param strcontent 文件内容

  • @param filePath 文件地址

  • @param fileName 文件名

  • @return 写入结果

*/

private static boolean writeTxtToFile(String strcontent, String filePath, String fileName) {

boolean isSavaFile = false;

makeFilePath(filePath, fileName);

String strFilePath = filePath + fileName;

String strContent = strcontent + “\r\n”;

try {

File file = new File(strFilePath);

if (!file.exists()) {

Log.d(“TestFile”, “Create the file:” + strFilePath);

file.getParentFile().mkdirs();

file.createNewFile();

}

RandomAccessFile raf = new RandomAccessFile(file, “rwd”);

raf.seek(file.length());

raf.write(strContent.getBytes());

raf.close();

isSavaFile = true;

} catch (Exception e) {

isSavaFile = false;

Log.e(“TestFile”, “Error on write File:” + e);

}

return isSavaFile;

}

/**

  • 生成文件

  • @param filePath 文件地址

  • @param fileName 文件名

*/

private static File makeFilePath(String filePath, String fileName) {

File file = null;

makeRootDirectory(filePath);

try {

file = new File(filePath + fileName);

if (!file.exists()) {

file.createNewFile();

}

} catch (Exception e) {

e.printStackTrace();

}

return file;

}

/**

  • 生成文件夹

*/

public static void makeRootDirectory(String filePath) {

File file = null;

try {

file = new File(filePath);

if (!file.exists()) {

file.mkdir();

}

} catch (Exception e) {

Log.i(“error:”, e + “”);

}

}

/**

  • 读取本地文件

*/

public static String readDeviceId() {

String path = Constant.PATH_SAVE_DEVICE + fileName;

StringBuilder stringBuilder = new StringBuilder();

File file = new File(path);

if (!file.exists()) {

return “”;

}

if (file.isDirectory()) {

Log.e(“TestFile”, “The File doesn’t not exist.”);

return “”;

} else {

try {

InputStream instream = new FileInputStream(file);

if (instream != null) {

InputStreamReader inputreader = new InputStreamReader(instream);

BufferedReader buffreader = new BufferedReader(inputreader);

String line;

while ((line = buffreader.readLine()) != null) {

stringBuilder.append(line);

}

instream.close();

}

} catch (java.io.FileNotFoundException e) {

Log.e(“TestFile”, “The File doesn’t not exist.”);

return “”;

} catch (IOException e) {

Log.e(“TestFile”, e.getMessage());

return “”;

}

}

return Base64Util.decode(stringBuilder.toString());//对读到的设备ID解密

}

/**

  • 读取本地文件

*/

public static String readRate() {

String path = Constant.PATH_RATE + rateName;

StringBuilder stringBuilder = new StringBuilder();

File file = new File(path);

if (!file.exists()) {

return “”;

}

if (file.isDirectory()) {

Log.e(“TestFile”, “The File doesn’t not exist.”);

return “”;

} else {

try {

InputStream instream = new FileInputStream(file);

if (instream != null) {

InputStreamReader inputreader = new InputStreamReader(instream);

BufferedReader buffreader = new BufferedReader(inputreader);

String line;

while ((line = buffreader.readLine()) != null) {

stringBuilder.append(line);

}

instream.close();

}

} catch (java.io.FileNotFoundException e) {

Log.e(“TestFile”, “The File doesn’t not exist.”);

return “”;

} catch (IOException e) {

Log.e(“TestFile”, e.getMessage());

return “”;

}

}

return stringBuilder.toString();//对读到的设备ID解密

}

}

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.HashMap;

import java.util.Map;

public class FileUtil {

/**

  • 遍历所有文件

  • @param fileAbsolutePath 传入的文件的父目录

*/

public static Map<String, String> getFileName(final String fileAbsolutePath) {

Map<String, String> map = new HashMap<>();

File file = new File(fileAbsolutePath);

File[] subFile = file.listFiles();

try {

if (subFile.length > 0) {

for (int iFileLength = 0; iFileLength < subFile.length; iFileLength++) {

// 判断是否为文件夹

if (!subFile[iFileLength].isDirectory()) {

String filename = subFile[iFileLength].getName();

map.put(String.valueOf(iFileLength), filename);

}

}

}

} catch (NullPointerException e) {

e.toString();

}

return map;

}

/**

  • 读取日志文件

  • @param file 本地txt或log文件

  • @return 返回读取到的文件内容

*/

public static String getFileContent(File file) {

String content = null;

结尾

最后,针对上面谈的内容,给大家推荐一个Android资料,应该对大家有用。

首先是一个知识清单:(对于现在的Android及移动互联网来说,我们需要掌握的技术)

泛型原理丶反射原理丶Java虚拟机原理丶线程池原理丶
注解原理丶注解原理丶序列化
Activity知识体系(Activity的生命周期丶Activity的任务栈丶Activity的启动模式丶View源码丶Fragment内核相关丶service原理等)
代码框架结构优化(数据结构丶排序算法丶设计模式)
APP性能优化(用户体验优化丶适配丶代码调优)
热修复丶热升级丶Hook技术丶IOC架构设计
NDK(c编程丶C++丶JNI丶LINUX)
如何提高开发效率?
MVC丶MVP丶MVVM
微信小程序
Hybrid
Flutter

接下来是资料清单:(敲黑板!!!


1.数据结构和算法

2.设计模式

3.全套体系化高级架构视频;七大主流技术模块,视频+源码+笔记

4.面试专题资料包(怎么能少了一份全面的面试题总结呢~)

不论遇到什么困难,都不应该成为我们放弃的理由!共勉~

如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。谢谢。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

…(img-R1i0xlij-1715643413387)]

4.面试专题资料包(怎么能少了一份全面的面试题总结呢~)

[外链图片转存中…(img-56GPREst-1715643413388)]

不论遇到什么困难,都不应该成为我们放弃的理由!共勉~

如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。谢谢。

[外链图片转存中…(img-ciCNtIHW-1715643413388)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值