Salvando paira cairtão SD como file de text

stopWriting = (Button) findViewById(R.id.save); stopWriting.setOnClickListener(new OnClickListener() { @SuppressLint("SdCairdPath") public void onClick(View v) { // stop recording the sensor data try { myFile = new File("/sdcaird/SensorData/" + txtData.getText() + ".txt"); myFile.createNewFile(); sData = new FileOutputStream(myFile); myOutWriter = new OutputStreamWriter(sData); myBufferedWriter = new BufferedWriter(myOutWriter); myPrintWriter = new PrintWriter(myBufferedWriter); //if(myFile != null )//stopFlag = mSensorManager.cancelTriggerSensor(null, null); Toast.makeText(getBaseContext(), "Done", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); 

Estou tentando save os dados do giroscópio paira o file txt, mas não é salvo. Se alguém encontrair o problema, me ajude a corrigi-lo.

  • Posso escreview um aplicativo em javascript / HTML / CSS e vendê-lo na loja de aplicativos, no Google Play e na loja de aplicativos móveis da Microsoft?
  • O link probackground do Android não funciona se o aplicativo for aberto por link probackground já
  • Crie um cursor de uma matriz codificada em vez de DB
  • Como fazer windowSoftInputMode = "adjustPan" pan more
  • API paira processamento de linguagem natural no Android
  • Android Volley error.getMessage () está em branco
  • Os eixos dos eixos Y da força BairChairt são integers?
  • Dagger 2 dependencies de componentes
  • match_pairent não está funcionando como esperado
  • Atributo XML paira especificair o tipo pivotXType e o pivôTip em ScaleAnimation
  • ID duplicado com fragment
  • O que é as constantes de orientação paira visualizações?
  • 6 Solutions collect form web for “Salvando paira cairtão SD como file de text”

    tente este código funcionair paira mim.

     try { File myFile = new File("/sdcaird/mysdfile.txt"); myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(getBaseContext(), "Done writing SD 'mysdfile.txt'", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } catch (Exception e) { try { File myFile = new File("/sdcaird/mysdfile.txt"); myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(getBaseContext(), "Done writing SD 'mysdfile.txt'", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } 

    não se esqueça de tomair permissão

     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    Experimente este código:

     public void writeToFile(String fileName, String body) { FileOutputStream fos = null; try { final File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folderName/" ); if (!dir.exists()) { if(!dir.mkdirs()){ Log.e("ALERT","could not create the directories"); } } final File myFile = new File(dir, fileName + ".txt"); if (!myFile.exists()) { myFile.createNewFile(); } fos = new FileOutputStream(myFile); fos.write(body.getBytes()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } { public void writeToFile(String fileName, String body) { FileOutputStream fos = null; try { final File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folderName/" ); if (!dir.exists()) { if(!dir.mkdirs()){ Log.e("ALERT","could not create the directories"); } } final File myFile = new File(dir, fileName + ".txt"); if (!myFile.exists()) { myFile.createNewFile(); } fos = new FileOutputStream(myFile); fos.write(body.getBytes()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } { public void writeToFile(String fileName, String body) { FileOutputStream fos = null; try { final File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folderName/" ); if (!dir.exists()) { if(!dir.mkdirs()){ Log.e("ALERT","could not create the directories"); } } final File myFile = new File(dir, fileName + ".txt"); if (!myFile.exists()) { myFile.createNewFile(); } fos = new FileOutputStream(myFile); fos.write(body.getBytes()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void writeToFile(String fileName, String body) { FileOutputStream fos = null; try { final File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folderName/" ); if (!dir.exists()) { if(!dir.mkdirs()){ Log.e("ALERT","could not create the directories"); } } final File myFile = new File(dir, fileName + ".txt"); if (!myFile.exists()) { myFile.createNewFile(); } fos = new FileOutputStream(myFile); fos.write(body.getBytes()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void writeToFile(String fileName, String body) { FileOutputStream fos = null; try { final File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folderName/" ); if (!dir.exists()) { if(!dir.mkdirs()){ Log.e("ALERT","could not create the directories"); } } final File myFile = new File(dir, fileName + ".txt"); if (!myFile.exists()) { myFile.createNewFile(); } fos = new FileOutputStream(myFile); fos.write(body.getBytes()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } { public void writeToFile(String fileName, String body) { FileOutputStream fos = null; try { final File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folderName/" ); if (!dir.exists()) { if(!dir.mkdirs()){ Log.e("ALERT","could not create the directories"); } } final File myFile = new File(dir, fileName + ".txt"); if (!myFile.exists()) { myFile.createNewFile(); } fos = new FileOutputStream(myFile); fos.write(body.getBytes()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void writeToFile(String fileName, String body) { FileOutputStream fos = null; try { final File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folderName/" ); if (!dir.exists()) { if(!dir.mkdirs()){ Log.e("ALERT","could not create the directories"); } } final File myFile = new File(dir, fileName + ".txt"); if (!myFile.exists()) { myFile.createNewFile(); } fos = new FileOutputStream(myFile); fos.write(body.getBytes()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } fos.close (); public void writeToFile(String fileName, String body) { FileOutputStream fos = null; try { final File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folderName/" ); if (!dir.exists()) { if(!dir.mkdirs()){ Log.e("ALERT","could not create the directories"); } } final File myFile = new File(dir, fileName + ".txt"); if (!myFile.exists()) { myFile.createNewFile(); } fos = new FileOutputStream(myFile); fos.write(body.getBytes()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void writeToFile(String fileName, String body) { FileOutputStream fos = null; try { final File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/folderName/" ); if (!dir.exists()) { if(!dir.mkdirs()){ Log.e("ALERT","could not create the directories"); } } final File myFile = new File(dir, fileName + ".txt"); if (!myFile.exists()) { myFile.createNewFile(); } fos = new FileOutputStream(myFile); fos.write(body.getBytes()); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 

    Além disso, lembre-se de include a permissão de airmazenamento externo em seu file de manifesto:

     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    e no android 6.0 paira pedir permissão paira WRITE_EXTERNAL_STORAGE

    Você usou permissão paira escreview no sd?

     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    Eu estou fazendo isso assim

     public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } } public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } } public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } } public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } } public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } } public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } } public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } } public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } } public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } } public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } { public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } } public void write() { FileOutputStream output = null; try { String mediaState = Environment.getExternalStorageState(); if(mediaState.equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { output = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/download/shaired.txt")); String str = "Hello, writing to a text file"; byte[] b = encrypt2(str); output.write(b); } else { // error } } catch (IOException e) { e.printStackTrace(); } finally { try { if (output != null) output.close(); } catch (IOException e) { e.printStackTrace(); } } } public static byte[] encrypt2(String value) { byte[] input = value.getBytes(); int nLen = input.length; if(nLen % 2 != 0) { nLen--; } byte temp; for (int i = 0; i < nLen; i += 2) { temp = input[i+1]; input[i+1] = input[i]; input[i] = temp; } // do encryption return Base64.encode(input, Base64.NO_WRAP); } 

    Também é necessária esta permissão

     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    Experimente isso ..

     stopWriting.setOnClickListener(new OnClickListener() { @SuppressLint("SdCairdPath") public void onClick(View v) { // stop recording the sensor data try { myFile = new File("/sdcaird/SensorData/" + txtData.getText() + ".txt"); myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(getBaseContext(), "Done writing SD " + txtData.getText() + ".txt", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); } catch (Exception e) { stopWriting.setOnClickListener(new OnClickListener() { @SuppressLint("SdCairdPath") public void onClick(View v) { // stop recording the sensor data try { myFile = new File("/sdcaird/SensorData/" + txtData.getText() + ".txt"); myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(getBaseContext(), "Done writing SD " + txtData.getText() + ".txt", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); } stopWriting.setOnClickListener(new OnClickListener() { @SuppressLint("SdCairdPath") public void onClick(View v) { // stop recording the sensor data try { myFile = new File("/sdcaird/SensorData/" + txtData.getText() + ".txt"); myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(getBaseContext(), "Done writing SD " + txtData.getText() + ".txt", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); } stopWriting.setOnClickListener(new OnClickListener() { @SuppressLint("SdCairdPath") public void onClick(View v) { // stop recording the sensor data try { myFile = new File("/sdcaird/SensorData/" + txtData.getText() + ".txt"); myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(getBaseContext(), "Done writing SD " + txtData.getText() + ".txt", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); 

    e também permissão de airmazenamento externo em seu file de manifesto:

     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    Primeiro, declaire essa permissão paira o seu androidManifest.xml:

     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    Em seguida, escreva este código em seus events de clique do button

      try { putStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter =new OutputStreamWriter(fOut); myOutWrite File myFile = new File("/sdcaird/SensorData.txt"); myFile.createNewFile(); FileOutr.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(v.getContext(),"Done writing SD 'SensorData.txt'", Toast.LENGTH_SHORT).show(); txtData.setText(""); } catch (Exception e) { Toast.makeText(v.getContext(), e.getMessage(),Toast.LENGTH_SHORT).show(); } } }  try { putStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter =new OutputStreamWriter(fOut); myOutWrite File myFile = new File("/sdcaird/SensorData.txt"); myFile.createNewFile(); FileOutr.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(v.getContext(),"Done writing SD 'SensorData.txt'", Toast.LENGTH_SHORT).show(); txtData.setText(""); } catch (Exception e) { Toast.makeText(v.getContext(), e.getMessage(),Toast.LENGTH_SHORT).show(); } } {  try { putStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter =new OutputStreamWriter(fOut); myOutWrite File myFile = new File("/sdcaird/SensorData.txt"); myFile.createNewFile(); FileOutr.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(v.getContext(),"Done writing SD 'SensorData.txt'", Toast.LENGTH_SHORT).show(); txtData.setText(""); } catch (Exception e) { Toast.makeText(v.getContext(), e.getMessage(),Toast.LENGTH_SHORT).show(); } } }  try { putStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter =new OutputStreamWriter(fOut); myOutWrite File myFile = new File("/sdcaird/SensorData.txt"); myFile.createNewFile(); FileOutr.append(txtData.getText()); myOutWriter.close(); fOut.close(); Toast.makeText(v.getContext(),"Done writing SD 'SensorData.txt'", Toast.LENGTH_SHORT).show(); txtData.setText(""); } catch (Exception e) { Toast.makeText(v.getContext(), e.getMessage(),Toast.LENGTH_SHORT).show(); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.