Tag Archives: file

7,797 views

Android Studio lock unlock file make read only or writable

Select file in project explorer Menu: File – Make File Read-only – to lock File – Make File Writable – to unlock

Posted in Android Studio | Tagged | Comments Off on Android Studio lock unlock file make read only or writable
2,052 views

External Storage read write file

AndroidManifest.xml <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> MyActivity.java /* Checks if external storage is available for read and write */ public boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; }       … Continue reading

Posted in Android Examples Code | Tagged | Comments Off on External Storage read write file
2,136 views

Java Basic Rules

// file name MyFirstClass.java   import java.util.*; import java.lang.Math; import java.io.*; import javax.swing.*;   public class MyFirstClass{ // start of program public static void main(String[] args) { // basic function main   // variables and calculation int a=2; int b=3; … Continue reading

Posted in Android Examples Code, Array,List,Collections | Tagged , , | Comments Off on Java Basic Rules
5,613 views

Open Save UTF-8 File To String Java Android Code

String sFileContent = readFile("myfile.txt",StandardCharsets.UTF_8);   static String readFile(String path, Charset encoding) throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(path)); return encoding.decode(ByteBuffer.wrap(encoded)).toString(); }   // write file String sOut = "text blah hello world etc."; writeToFile(sOut"someName.txt"); static void writeToFile(String sB,String name) { … Continue reading

Posted in Android Examples Code | Tagged | Comments Off on Open Save UTF-8 File To String Java Android Code
18,948 views

Write new file or append text Java Android example

BufferedWriter, FileWriter, write, close MODE_APPEND Java and Android example Write to file Android example try { String MYFILE = "my_file"; String strText = "My text";   // MODE_APPEND, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE // create new file or rewrite existing FileOutputStream fos = … Continue reading

Posted in Android Examples Code | Tagged , , , | Comments Off on Write new file or append text Java Android example
6,167 views

File open read to StringBuilder close Java example

BufferedReader , FileReader, StringBuilder , readLine, close Java example Android example String MYFILE = "my_file"; FileInputStream fis = openFileInput(MYFILE); int c; String sText = ""; while((c=fis.read())!=-1) {   sText += (char)c; // convert int to char } fis.close(); Java example … Continue reading

Posted in Android Examples Code | Tagged , , , , , | Comments Off on File open read to StringBuilder close Java example
8,373 views

Get text file content from raw folder to StringBuilder Android example

StringBuilder, res/raw folder, try catch finaly throws, BufferedReader, InputStream, openRawResource, getResources Android example MainActivity.java   public class MainActivity extends Activity { TextView txtV; Context cntx;   @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); txtV = (TextView)findViewById(R.id.idLabel); cntx = this; … Continue reading

Posted in Android Examples Code | Tagged , , , , , , | Comments Off on Get text file content from raw folder to StringBuilder Android example
19,240 views

Get assets folder files to array of strings Android example

Get assets folder files to array of strings. Its show files in assets folder and sub folders: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);   final AssetManager assetManager = getAssets(); try { // for assets folder add empty string String[] … Continue reading

Posted in Android Examples Code | Tagged , , , , , , , | Comments Off on Get assets folder files to array of strings Android example
54,757 views

Get Assets folder path and read txt file to string Android example code

Programmatically load text from Asset folder file myData.txt to string Android example source code. Read file to byte[] buffer and convert into string Android example. Assets folder path may be: c:\documents\_android_projects\MyProject\assets // Path for a WebView String sAssets = "file:///android_asset/" … Continue reading

Posted in Android Examples Code | Tagged , , , , , , | Comments Off on Get Assets folder path and read txt file to string Android example code
4,699 views

Read file from URL

Read file from URL to array of byte and convert to UTF-8 String Android examle source code. URL urlLoc = new URL("http://myweb.com/myfile.html"); URLConnection conexion = urlLoc.openConnection(); conexion.setConnectTimeout(4000); conexion.setReadTimeout(1000); conexion.connect();   // downlod the file InputStream input = new BufferedInputStream(urlLoc .openStream()); … Continue reading

Posted in Android Examples Code | Tagged , , , , , | Comments Off on Read file from URL