發表文章

目前顯示的是 8月, 2022的文章

Android Studio .csv檔讀寫

圖片
 Android Studio .csv檔讀寫 可以先參考 Android Studio 檔案讀寫 內有寫關於Android Studio讀寫檔案基礎介紹 本次使用ArrayList存放CSV資料,使用RecyclerView顯示資料 建立ArrayList Data Model 新增DataModel的Java class public class DataModel { private String ID ; private String Name ; private String Score ; public DataModel (String ID , String Name , String Score){ this . ID = ID ; this . Name = Name ; this . Score = Score ; } public String getID (){ return ID ; } public String getName (){ return Name ; } public String getScore (){ return Score ; } } 並在Activity內宣告ArrayList ArrayList<DataModel> datalist = new ArrayList<>() 建立RecyclerView & Adapter 在建立Adapter之前可以先建立ViewHolder public class ViewHolder extends RecyclerView.ViewHolder { public TextView idtext , nametext , scoretext ; public ViewHolder ( @NonNull View itemView) { super (itemView) ; i...

Android Studio 寫入檔案PC無法顯示

Android Studio 寫入檔案PC無法顯示 寫入檔案後需要使系統重新掃描檔案 可以使用以下方式 1. Intent intent = new Intent(Intent. ACTION_MEDIA_SCANNER_SCAN_FILE ) ; Uri uri = Uri. fromFile (newTextFile) ; intent.setData(uri) ; context .sendBroadcast(intent) ; 2. MediaScannerConnection. scanFile ( context ,new String[]{file.getAbsolutePath()} ,null,null ) ;

Android Studio 檔案讀寫

圖片
 Android Studio 檔案讀寫 讀寫權限 <uses-permission android :name ="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android :name ="android.permission.WRITE_EXTERNAL_STORAGE" /> 取得儲存路徑 getDataDirectory() 取得手機內存根目錄 getDownloadCacheDirectory() 取得手機暫存 getRootDirectory() 取得手機系統目錄 getExternalStorageDirectory() 取得手機外部儲存SD Card目錄 取得路徑的格式 getPath() 取得定義的路徑 getAbsolutePath() 取得絕對路徑 getCanonicalPath() 取得符合路徑規範的路徑 File file = new File( "TXT/./test.txt" ) ; Log. d ( "frilgetPath" , "==" +file.getPath()) ; Log. d ( "frilAbsolutePath" , "==" +file.getAbsolutePath()) ;...