Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write String to txt file and send it to server
    primarykey
    data
    text
    <p>I want to develop an application in android in which I need to capture image and convert that image to string and write that string in txt file and send it to server where server reads that file and convert that string to image again...</p> <p>now i have done with image taking part and converting that image into string and writing that string to txt file.</p> <p>but when am try to read that file and convert that string into the image it's not working...</p> <p>Code for converting image into string is</p> <pre><code>File imageFile = new File(path); Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath()); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream); byte[] image = stream.toByteArray(); imgstr = Base64.encodeToString(image, 0); </code></pre> <p>Code for writing that into file is</p> <pre><code>File file = new File("new.txt"); FileWriter w = new FileWriter("/sdcard/new/new.txt"); BufferedWriter out = new BufferedWriter(w); out.write(data); out.flush(); out.close(); </code></pre> <p>And code for read that file and convert that string to image again is</p> <pre><code>FileInputStream fstream = new FileInputStream("/sdcard/new/new.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; ArrayList list=new ArrayList(); while ((strLine = br.readLine()) != null) { list.add(strLine); } Iterator itr; for (itr=list.iterator(); itr.hasNext(); ) { String str=itr.next().toString(); StringBuffer sb=new StringBuffer(str); int length=sb.length(); String imageDataString = sb.substring(0, length); byte[] decodedString = Base64.decode(imageDataString, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0,decodedString.length); FileOutputStream imageOutFile = new FileOutputStream("/sdcard/new/android.jpg"); imageOutFile.write(decodedString); imageOutFile.close(); System.out.println("File converted"); </code></pre> <p>but its not converting that string into image please tell me solution for it...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload