Re: [android-developers] Re: very urgent.. problem in writing file..

2010-03-13 Thread kumaresh
 Before , writing to SDCARD - its preferred to get the state of it.

 private boolean isSDCARDMounted(){
String status = Environment.getExternalStorageState();

if (status.equals(Environment.MEDIA_MOUNTED))
return true;
return false;
}

 http://developer.android.com/intl/de/reference/android/os/Environment.html

On Sat, Mar 13, 2010 at 1:57 PM, Bob Kerns  wrote:

> Resources aren't even IN the filesystem. They're packaged up in
> the .apk file, and are read-only.
>
> You CAN write to the application's private storage area.  This will
> work even if the device does not have an SD card. However, this
> storage is limited; it may be better for you to use the SD card.
>
> In your example, you give it a path that refers to several levels of
> directory that don't exist - and openFileOutput() is documented as
> taking a file NAME, not a path. But you can use getDir(name, mode) to
> create a directory (and control access) and then create files in that
> via the normal Java APIs.
>
> If you choose to put it on the SD card, follow TreKing's advice,
> except the API is called Environment.getExternalStorageDirectory().
> You can do
>
> File myDir = new File(Environment.getExternalStorageDirectory(),
> getPackageName())
> mydir.mkdir();
> Writer out = new FileWriter(myDir);
>
> But since you seem to be concerned about the large amount of data, you
> may want to change how you approach it. The resource can be the
> default data, and you put additional data or new data that replaces it
> in a file. Your application would first consult the file, and if not
> found, it would then consult the resource. This would avoid the need
> to copy the resource out into the filesystem to modify it.
>
> On Mar 12, 6:07 am, RV  wrote:
> > Hi,
> > I am stuck on this for a very long.
> > I have my txt file in res/raw/myfile.txt.
> > I want to append some text into this file. But I am unable to do so.
> > I used the code as follows:
> >
> >  FileOutputStream out = context.openFileOutput(
> >
> "res/raw/myfile.txt",
> >
> Context.MODE_WORLD_WRITEABLE
> > |
> Context.MODE_APPEND);
> >
> >  OutputStreamWriter osw = new
> OutputStreamWriter(out);
> >
> >osw.write(entry);
> >osw.flush();
> >osw.close();
> >
> > It is not giving any error but also do nothing  to my file.
> >
> > Also How could I edit only the 1st line of my file. (my file contain
> > huge data.)
> >
> > Any help will be appreciated.
> >
> > Thank you
> >
> > RV
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
--kumaresan

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Content Length -1 in HTTP Response / Parial Read

2010-02-18 Thread kumaresh
Hi,
  1. Implemented an application, that does a webservice call to our
servers. when the response size is around 200 Kb, iam receiving the
content length as -1. It works well in Droid/ADP1/etc (receiving the
original length) but fails in HTC My Touch and HTC DREAM.

  2. When i replace, the content length , with 20 , when the
content length is -1. Still, cannot able to read the complete chunk
from the input stream.

This issue can be in other devices too.
The issue could be with the buffer size/allocation ?



Here is that piece of code:
 private byte[] doHttpRequest(String url,String req) throws
IOException {
InputStream is = null;
HttpURLConnection c = null;
   OutputStream os = null;

String errMsg = null;
try {

c = (HttpURLConnection) new URL(url)
.openConnection();

c.setDoInput(true);
c.setDoOutput(true);
c.setConnectTimeout(15000);
c.setReadTimeout(4);
c.setRequestMethod("POST");
   c.setRequestProperty("Content-Language", "en-US");
   os=c.getOutputStream();
   os.write(("mobile_request=" +
StringStuff 
.URLEncodeStr(req).getBytes());
rc = c.getResponseCode();
if (rc != HttpURLConnection.HTTP_OK) {

throw new IllegalResponseCodeException("HTTP 
response code: "
+ rc);
}
is = c.getInputStream();
int len = (int) c.getContentLength();
// Length=-1 , incase of HTC DREAM/HTC Touch
if (len > 0) {
int actual = 0;
int bytesread = 0;
byte[] data = new byte[len];
while ((bytesread != len) && (actual != -1)) {
actual = is.read(data, bytesread, len - 
bytesread);
bytesread += actual;
}
return data;
}
}
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en