拉大锯老师第《【android基础系列P3】Android开发数据持久化存储》系列JAVA重用kotlin写遇到了问题
代码如下,现在能运行 能安装就是在输入账号密码之后,无法春昂见
class MainActivity : AppCompatActivity(),View.OnClickListener{
private var mAccount: EditText? = null
private var mPassword: EditText? = null
private var mlogin: Button? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
initView()
ininListener()
}
private fun ininListener() {
mlogin!!.setOnClickListener { v -> handlerLoginEvent(v) }
}
private fun handlerLoginEvent(v: View) {
val accountText = mAccount!!.text.toString()
val passwordText = mPassword!!.text.toString()
saveUserInfo(accountText, passwordText)
}
private fun saveUserInfo(accountText: String, passwordText: String) {
Log.d(TAG, "保存了用户信息")
// File fileDir=this.getFilesDir();
// Log.d(TAG,"filesDir==="+fileDir.toString());
var fileDir=this.getFilesDir();
Log.d(TAG,"+++++"+fileDir)
try {
val file = File("/data/user/0/ymbky.example.suizai/files/info.text")
if (!file.exists()) {
file.createNewFile()
}
val fos = FileOutputStream(file)
fos.write("$accountText****$passwordText".toByteArray())
fos.close()
} catch (e: Exception) {
e.printStackTrace()
}
}
private fun initView() {
mAccount = findViewById(R.id.et_account)
mPassword = findViewById(R.id.et_password)
mlogin = findViewById(R.id.bt_login)
}
companion object {
private const val TAG = "MainActivity"
}
override fun onClick(v: View?) {
TODO("Not yet implemented")
}
现在经过测试可以确定在
private fun handlerLoginEvent(v: View) {
val accountText = mAccount!!.text.toString()
val passwordText = mPassword!!.text.toString()
saveUserInfo(accountText, passwordText)
}
这一步能够拿到输入的账号密码,但是写不出来 ,大佬帮忙看一下
最新消息 换了种写法
这样试了一下 创建成功了 还是路径问题
文件创建了吗?log输出是啥?功能上走到了哪步了?