I want to read out a file in Android and get the content as a string. Then I want to send it to a server. But for testing I just create a file on the device and put the content into it:
InputStream stream = getContentResolver().openInputStream(fileUri);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
File dir = new File (Environment.getExternalStorageDirectory() + "/Android/data/" + getPackageName());
if(!dir.exists())
dir.mkdirs();
File file = new File(dir, "output."+format); // format is "txt", "png" or sth like that
if(!file.exists())
file.createNewFile();
BufferedWriter writer = null;
writer = new BufferedWriter(new FileWriter(file));
String line = reader.readLine();
while (line != null)
{
writer.write(line);
line = reader.readLine();
if(line != null)
writer.write("\n");
}
writer.flush();
writer.close();
stream.close();
This works for txt files but when I for example try to copy a pdf file it is openable but just white.
Can anyone help me?
Thanks
Hello, world>`. PDF is much like that, except it allows for the use of a lot of other data types as well, like bezier curves and it has official documentation which tells you how to construct and read a PDF file.
– D. Visser May 12 '15 at 16:28