Hello I am reading one image and convert that image to Base64 format
and write that to one txt file. But my code is not working properly. I
had not get correct output .(txt file is not correctly written),
Actually size of txt file has to be around 155kb but my txt file size
is about 266kb. here is my code
public class ImageUp extends Activity
{
File readFile = new File("/sdcard/Images/c.jpeg");
File writeFile = new File("/sdcard/Images/Image.txt");
FileWriter fw;
PrintWriter pw;
FileInputStream fstream;
String str,base64String;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
writeFile.createNewFile();
fw = new FileWriter(writeFile);
pw = new PrintWriter(fw);
readFile();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void readFile()
{
try
{
byte[] byteArray = new byte[102400];
fstream = new FileInputStream(readFile);
int bytesRead = 0;
while((bytesRead = fstream.read(byteArray)) != -1)
{
str = new String(byteArray,0,bytesRead);
base64String = Base64.encode(byteArray);
writeFile(base64String);
System.out.println (base64String);
}
pw.flush();
pw.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void writeFile(String data)
{
pw.print(data);
}
}
I have Base64 class which accept byte array and return a String. what
is wrong in this code?
Thanks in advance.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en