0
  • 我的妈耶,C:\\Users\\prnck\\AndroidStudioProjects\\Demo\\info.textzh这不是手机的啊
    
    n你需要拿手机的路径才行。
    
    Environment.getExternalStorageState()
    w外部的,可以看看Environment
    
    r如果是app内部安装目录,可以用context getCache,等等来写文件,这个不用权限的
    
    1139423796017500160  评论     打赏       断点-含光君
    • 代码:

      package com.example.demo;
      
      import android.os.Bundle;
      import android.util.Log;
      import android.view.View;
      import android.widget.Button;
      import android.widget.EditText;
      
      import androidx.appcompat.app.AppCompatActivity;
      
      import java.io.File;
      import java.io.FileOutputStream;
      
      public class QQLogin extends AppCompatActivity implements View.OnClickListener {
      
          private static final String TAG = "QQLogin";
          private EditText mAccount;
          private EditText mPassword;
          private Button mBtnLogin;
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_qqlogin);
              initView();
              initListener();
          }
      
          private void initListener() {
              mBtnLogin.setOnClickListener(this);
          }
      
          private void initView() {
              mAccount = findViewById(R.id.et_account);
              mPassword = findViewById(R.id.et_password);
              mBtnLogin = findViewById(R.id.btn_login);
          }
      
          @Override
          public void onClick(View view) {
              switch (view.getId()){
                  case R.id.btn_login:
                      Log.d(TAG, "点击了登录按钮");
                      handlerLoginEvent(view);
              }
          }
      
          private void handlerLoginEvent(View view) {
              //拿到界面的内容,包括账号和密码
              //账号
              String accountText = mAccount.getText().toString();
              //密码
              String passwordText = mPassword.getText().toString();
      
              //把账号和密码保存起来
              //以一个文件的方式来保存
              saveUserInfo(accountText, passwordText);
          }
      
      
          private void saveUserInfo(String accountText, String passwordText) {
              Log.d(TAG, "保存用户信息");
              File file = new File("C:\\Users\\prnck\\AndroidStudioProjects\\Demo\\info.text");
              try {
              if (!file.exists()) {
                  file.createNewFile();
              }
                  FileOutputStream fos = new FileOutputStream(file);
                  //以特定的方式去存储
                  //存储形式:账号****密码
                  fos.write((accountText + "****" + passwordText).getBytes());
      
                  fos.close();
              } catch (Exception e) {
                  e.printStackTrace();
              }
      
      
          }
      }
      
      



      报错:

      2022-01-17 10:32:19.498 5275-5275/com.example.demo I/om.example.dem: Late-enabling -Xcheck:jni

      2022-01-17 10:32:19.512 5275-5275/com.example.demo E/om.example.dem: Unknown bits set in runtime_flags: 0x8000

      2022-01-17 10:32:20.085 5275-5275/com.example.demo I/Perf: Connecting to perf service.

      2022-01-17 10:32:20.099 5275-5275/com.example.demo I/FeatureParser: can't find apollo.xml in assets/device_features/,it may be in /vendor/etc/device_features

      2022-01-17 10:32:20.106 5275-5275/com.example.demo E/libc: Access denied finding property "ro.vendor.df.effect.conflict"

      2022-01-17 10:32:20.106 5275-5275/com.example.demo E/libc: Access denied finding property "ro.vendor.knock.type"

      2022-01-17 10:32:20.144 5275-5275/com.example.demo D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.demo activity: com.example.demo.MainActivity@19851fb

      2022-01-17 10:32:20.146 5275-5275/com.example.demo D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.demo activity: com.example.demo.MainActivity@19851fb

      2022-01-17 10:32:20.149 5275-5342/com.example.demo I/om.example.dem: The ClassLoaderContext is a special shared library.

      2022-01-17 10:32:20.155 5275-5342/com.example.demo I/om.example.dem: The ClassLoaderContext is a special shared library.

      2022-01-17 10:32:20.166 5275-5275/com.example.demo W/om.example.dem: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)

      2022-01-17 10:32:20.166 5275-5275/com.example.demo W/om.example.dem: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)

      2022-01-17 10:32:20.169 5275-5342/com.example.demo W/om.example.dem: Accessing hidden method Lmiui/contentcatcher/sdk/Token;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V (greylist, linking, allowed)

      2022-01-17 10:32:20.170 5275-5342/com.example.demo W/om.example.dem: Accessing hidden method Lmiui/contentcatcher/InterceptorProxy;->getWorkThread()Landroid/os/HandlerThread; (greylist, linking, allowed)

      2022-01-17 10:32:20.170 5275-5342/com.example.demo D/ViewContentFactory: initViewContentFetcherClass

      2022-01-17 10:32:20.170 5275-5342/com.example.demo D/ViewContentFactory: getInterceptorPackageInfo

      2022-01-17 10:32:20.170 5275-5342/com.example.demo W/om.example.dem: Accessing hidden method Landroid/app/AppGlobals;->getInitialApplication()Landroid/app/Application; (greylist, linking, allowed)

      2022-01-17 10:32:20.170 5275-5342/com.example.demo D/ViewContentFactory: getInitialApplication took 0ms

      2022-01-17 10:32:20.170 5275-5342/com.example.demo D/ViewContentFactory: packageInfo.packageName: com.miui.catcherpatch

      2022-01-17 10:32:20.172 5275-5275/com.example.demo D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.demo activity: com.example.demo.MainActivity@19851fb

      2022-01-17 10:32:20.172 5275-5275/com.example.demo I/chatty: uid=10288(com.example.demo) identical 1 line

      2022-01-17 10:32:20.176 5275-5275/com.example.demo D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.demo activity: com.example.demo.MainActivity@19851fb

      2022-01-17 10:32:20.180 5275-5342/com.example.demo D/ViewContentFactory: initViewContentFetcherClass took 10ms

      2022-01-17 10:32:20.180 5275-5342/com.example.demo I/ContentCatcher: ViewContentFetcher : ViewContentFetcher

      2022-01-17 10:32:20.180 5275-5342/com.example.demo D/ViewContentFactory: createInterceptor took 11ms

      2022-01-17 10:32:20.181 5275-5342/com.example.demo W/om.example.dem: Accessing hidden method Lmiui/contentcatcher/sdk/ContentCatcherManager;->getInstance()Lmiui/contentcatcher/sdk/ContentCatcherManager; (greylist, linking, allowed)

      2022-01-17 10:32:20.181 5275-5342/com.example.demo W/om.example.dem: Accessing hidden method Lmiui/contentcatcher/sdk/ContentCatcherManager;->registerContentInjector(Lmiui/contentcatcher/sdk/Token;Lmiui/contentcatcher/sdk/injector/IContentDecorateCallback;)V (greylist, linking, allowed)

      2022-01-17 10:32:20.182 5275-5342/com.example.demo W/om.example.dem: Accessing hidden method Lmiui/contentcatcher/sdk/ContentCatcherManager;->getPageConfig(Lmiui/contentcatcher/sdk/Token;)Lmiui/contentcatcher/sdk/data/PageConfig; (greylist, linking, allowed)

      2022-01-17 10:32:20.182 5275-5342/com.example.demo W/om.example.dem: Accessing hidden method Lmiui/contentcatcher/sdk/data/PageConfig;->getFeatures()Ljava/util/ArrayList; (greylist, linking, allowed)

      2022-01-17 10:32:20.182 5275-5342/com.example.demo W/om.example.dem: Accessing hidden method Lmiui/contentcatcher/sdk/data/PageConfig;->getCatchers()Ljava/util/ArrayList; (greylist, linking, allowed)

      2022-01-17 10:32:20.198 5275-5275/com.example.demo W/ActivityThread: SCHED: com.example.demo/.MainActivity [69, r=9ms, a=4ms, w=15ms]

      2022-01-17 10:32:20.221 5275-5337/com.example.demo I/AdrenoGLES-0: QUALCOMM build          : a676c8e, I49c2a65814

        Build Date            : 10/15/20

        OpenGL ES Shader Compiler Version: EV031.29.00.15

        Local Branch           : 

        Remote Branch          : refs/tags/AU_LINUX_ANDROID_LA.UM.8.12.R1.10.00.00.561.106

        Remote Branch          : NONE

        Reconstruct Branch        : NOTHING

      2022-01-17 10:32:20.221 5275-5337/com.example.demo I/AdrenoGLES-0: Build Config           : S P 8.0.12 AArch64

      2022-01-17 10:32:20.221 5275-5337/com.example.demo I/AdrenoGLES-0: Driver Path           : /vendor/lib64/egl/libGLESv2_adreno.so

      2022-01-17 10:32:20.226 5275-5337/com.example.demo I/AdrenoGLES-0: PFP: 0x016dd087, ME: 0x00000000

      2022-01-17 10:32:20.357 5275-5275/com.example.demo W/ActivityThread: SCHED: com.example.demo/.MainActivity [52, r=34ms, a=31ms, w=154ms]

      2022-01-17 10:32:22.347 5275-5275/com.example.demo I/Timeline: Timeline: Activity_launch_request time:6768023

      2022-01-17 10:32:22.358 5275-5275/com.example.demo W/ActivityThread: SCHED: com.example.demo/.MainActivity [74, r=20ms, a=7ms, w=603ms]

      2022-01-17 10:32:22.365 5275-5275/com.example.demo W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@5e91926

      2022-01-17 10:32:22.370 5275-5342/com.example.demo D/ViewContentFactory: initViewContentFetcherClass

      2022-01-17 10:32:22.370 5275-5342/com.example.demo I/ContentCatcher: ViewContentFetcher : ViewContentFetcher

      2022-01-17 10:32:22.370 5275-5342/com.example.demo D/ViewContentFactory: createInterceptor took 0ms

      2022-01-17 10:32:22.371 5275-5275/com.example.demo D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.demo activity: com.example.demo.QQLogin@93da1b2

      2022-01-17 10:32:22.399 5275-5275/com.example.demo I/chatty: uid=10288(com.example.demo) identical 8 lines

      2022-01-17 10:32:22.400 5275-5275/com.example.demo D/ForceDarkHelper: updateByCheckExcludeList: pkg: com.example.demo activity: com.example.demo.QQLogin@93da1b2

      2022-01-17 10:32:24.566 5275-5275/com.example.demo D/QQLogin: 点击了登录按钮

      2022-01-17 10:32:24.567 5275-5275/com.example.demo D/QQLogin: 保存用户信息

      2022-01-17 10:32:24.567 5275-5275/com.example.demo W/System.err: java.io.IOException: Read-only file system

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at java.io.UnixFileSystem.createFileExclusively0(Native Method)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at java.io.File.createNewFile(File.java:1008)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at com.example.demo.QQLogin.saveUserInfo(QQLogin.java:66)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at com.example.demo.QQLogin.handlerLoginEvent(QQLogin.java:57)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at com.example.demo.QQLogin.onClick(QQLogin.java:44)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at android.view.View.performClick(View.java:7300)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at android.view.View.performClickInternal(View.java:7277)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at android.view.View.access$3600(View.java:822)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at android.view.View$PerformClick.run(View.java:28027)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at android.os.Handler.handleCallback(Handler.java:914)

      2022-01-17 10:32:24.568 5275-5275/com.example.demo W/System.err:   at android.os.Handler.dispatchMessage(Handler.java:100)

      2022-01-17 10:32:24.569 5275-5275/com.example.demo W/System.err:   at android.os.Looper.loop(Looper.java:239)

      2022-01-17 10:32:24.569 5275-5275/com.example.demo W/System.err:   at android.app.ActivityThread.main(ActivityThread.java:7604)

      2022-01-17 10:32:24.569 5275-5275/com.example.demo W/System.err:   at java.lang.reflect.Method.invoke(Native Method)

      2022-01-17 10:32:24.569 5275-5275/com.example.demo W/System.err:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)

      2022-01-17 10:32:24.569 5275-5275/com.example.demo W/System.err:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:953)

      2022-01-17 10:35:01.169 5275-5275/com.example.demo W/ActivityThread: SCHED: com.example.demo/.QQLogin [93, r=116ms, a=8ms, w=158767ms]

      2022-01-17 10:35:01.822 5275-5342/com.example.demo W/om.example.dem: Accessing hidden method Lmiui/contentcatcher/sdk/ContentCatcherManager;->unregisterContentInjector(Lmiui/contentcatcher/sdk/Token;)V (greylist, linking, allowed)



      adb:

      C:\Users\prnck\AndroidStudioProjects\Demo>adb remount

      Not running as root. Try "adb root" first.

      remount failed


      C:\Users\prnck\AndroidStudioProjects\Demo>adb root

      adbd cannot run as root in production builds


      1482891406958780418  评论     打赏       prnck
      • 把代码放出来,不知道你在干嘛

        1139423796017500160  评论     打赏       断点-含光君
        • prnck  回复 @断点-含光君
          放出来了
          prnck 2022-01-17 10:37   回复 1482891406958780418
        • 拉大锯  回复 @prnck
          视频里也没这么教的呀[捂脸],你给个windows的路径?猝不及防呀。
          拉大锯 2022-01-17 10:46   回复 1153952789488054272
        • prnck  回复 @拉大锯
          但是视频我跟到adb remount那一步然后就不行了,是要root吗 我把路径改成/data/data/com.example.demo/info.text就没有报java.io.IOException: Read-only file system
          prnck 2022-01-17 10:55   回复 1482891406958780418
        • 拉大锯  回复 @prnck
          你的是release版本,remount不了。但你使用自己的目录是可以的。通过API去获取路径。
          拉大锯 2022-01-17 10:59   回复 1153952789488054272
      • 你的路径是啥呢?

        1153952789488054272  评论     打赏       拉大锯
        • prnck  回复 @拉大锯
          什么路径,存储账号密码的文件路径吗
          prnck 2022-01-17 09:52   回复 1482891406958780418
        • 拉大锯  回复 @prnck
          你读写文件的路径
          拉大锯 2022-01-17 10:08   回复 1153952789488054272
        • prnck  回复 @拉大锯
          "C:\\Users\\prnck\\AndroidStudioProjects\\Demo\\info.text"
          prnck 2022-01-17 10:30   回复 1482891406958780418
      相关问题
      1212121er · 临时Root
      2020-03-04 00:04 392 2
      搬砖小后 · Android命名空间
      2022-05-23 10:53 18 2
      什本先生 · 真机
      2022-05-20 12:13 59 2
      Xiao9mmDa · gradle版本
      2022-05-18 15:25 18 20
      呆瓜小董 · git
      2022-05-16 18:50 25 2
      阿淳言出必行 · recyclerView
      2022-05-12 14:48 40 10
      希望程序能按我想的那样运行 · 安卓学习
      2022-05-11 16:33 31 3
      Cstri · MVP
      2022-05-11 14:29 26 5
      2022-05-10 14:13 16 8
      Cstri · android
      2022-05-10 09:40 21 3