im trying to read a txt file downloaded from an arduino server. I can download the file and save it on internal storage, but when i want to read it, i see weird symbols and i can't see all saved text, only 6 o 7 characters. I don't know what happen.
public void downloadFile (String fileDownloadPath, String saveFilePath){
try{
File SaveFile = new File(saveFilePath);
URL u= new URL ("http://169.254.0.1:44300/169.254.0.1");
URLConnection con=u.openConnection();
int lengthofContent=con.getContentLength();
DataInputStream DIStream = new DataInputStream(u.openStream());
byte [] buffer = new byte[2000];
DIStream.read(buffer);
DIStream.close();
DataOutputStream DOStream = new DataOutputStream(new FileOutputStream(SaveFile));
DOStream.write(buffer);
DOStream.flush();
DOStream.close();
System.out.println ("o");
hideProgressIndicator();
} catch (FileNotFoundException e){
hideProgressIndicator();
}
catch (IOException e){
hideProgressIndicator();
}
catch (Exception e){
}
}
when i want to read it i use this:
private String readFile() {
String result = "", line;
try
{
BufferedReader br = new BufferedReader((new FileReader("/data/data/com.example.sensolog/files/LOL.txt")));
while((line = br.readLine()) != null)
{
result += line + "\n";
}
System.out.println (result);
br.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return result ;
}
And the results are the followings :
08-26 15:38:11.498: I/System.out(30593): SERVIDORn�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������...