Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

File under data/data/<package_name>/files not showing in my Android Device

I am making an app that will fetch the server logs and store it in end-users android phone. I am reading and writing the file using InputStream and FileOutputStream which generates a new text file under data/data/<package_name>/files folder of Emulator. However, it is not showing in my physical android device when connected through USB. Used below logic:

   try{
        Session session = new JSch().getSession(user, host, port);
        session.setPassword(password);
        session.setConfig("StrictHostKeyChecking", "no");
        session.connect();
        ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
        sftpChannel.connect();
        InputStream inputStream = sftpChannel.get(remoteFile);

        try (Scanner scanner = new Scanner(new InputStreamReader(inputStream))) {
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                logs.append(line);
            }
            try {
                FileOutputStream fos = null;
                fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
                fos.write(logs.getBytes());
                Toast.makeText(this, "File Saved", Toast.LENGTH_SHORT).show();
            }
            catch(FileNotFoundException e){
                 e.printStackTrace();
        }
        catch (JSchException | SftpException e) {
        e.printStackTrace();
     }

Is there any way, I could view this file in my phone without rooting and giving some permissions or any better alternative? Highly appreciate your inputs guys.

Device File Explorer Snapshot

question from:https://stackoverflow.com/questions/66051626/file-under-data-data-package-name-files-not-showing-in-my-android-device

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...