Android File存储(文件的存储路径)

仓廪实则知礼节,衣食足则知荣辱。这篇文章主要讲述Android File存储:文件的存储路径相关的知识,希望能为你提供帮助。
 

package com.gatsby.filepath; import android.os.Bundle; import android.os.Environment; import android.util.Log; import androidx.appcompat.app.AppCompatActivity; 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.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity {@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //内置Sdcard/mnt/internal_sd String internalPath = Environment.getExternalStorageDirectory().toString(); Log.d("gatsby", "path0-> " + internalPath); //U盘挂载路径 /mnt/usb_storage/USB_DISK2/udisk0 String usbPath = searchPath(); Log.d("gatsby", "path2-> " + usbPath); }public String searchPath() { String filePath = "/proc/mounts"; File file = new File(filePath); List< String> lineList = new ArrayList< > (); InputStream inputStream = null; try { inputStream = new FileInputStream(file); if (inputStream != null) { InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "GBK"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String line = ""; while ((line = bufferedReader.readLine()) != null) { if (line.contains("vfat")) { lineList.add(line); } } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } String editPath = lineList.get(lineList.size() - 1); int start = editPath.indexOf("/mnt"); int end = editPath.indexOf(" vfat"); String path = editPath.substring(start, end); return path; }}

【Android File存储(文件的存储路径)】 

    推荐阅读