Discussion:
Getting error when trying to read file : java.lang.IllegalArgumentException: File /data/testing.txt contains a path separator
Chandrakar Aravind-rqj386
2008-12-10 14:18:15 UTC
Permalink
Hi,



I am trying to read non-local txt file, but I am getting error:



java.lang.IllegalArgumentException: File /data/testing.txt
contains a path separator



Any one has any idea?



My code is like that:

FileInputStream orifile = openFileInput("/data//samplefile.txt");

BufferedReader bufReader = new BufferedReader(new
FileReader(orifile.getFD()));

I am able to read local file (created on my package).

Arvind


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers-***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---
Mark Murphy
2008-12-10 14:22:10 UTC
Permalink
Post by Chandrakar Aravind-rqj386
java.lang.IllegalArgumentException: File /data/testing.txt
contains a path separator
You probably don't have a file at /data/testing.txt.
Post by Chandrakar Aravind-rqj386
FileInputStream _orifile_ =
openFileInput("/data//_samplefile_._txt_");
openFileInput() accepts relative paths only. No leading slashes are
allowed. openFileInput() represents files stored in an
application-specific storage area. getFilesDir() will tell you where
this is, IIRC.
--
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.9 Available!
Chandrakar Aravind-rqj386
2008-12-10 15:41:41 UTC
Permalink
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=googlegroups.com; s¾ta;
h=x-sender:x-apparently-to:received-spf:authentication-results
:x-viruschecked:x-env-sender:x-msg-ref:x-starscan-version
:x-originating-ip:x-mimeole:content-class:mime-version:content-type
:content-transfer-encoding:subject:date:message-id:in-reply-to
:x-ms-has-attach:x-ms-tnef-correlator:thread-topic:thread-index
:references:from:to:cc:x-cfilter-loop:reply-to:sender:precedence
:x-google-loop:mailing-list:list-id:list-post:list-help
:list-unsubscribe:x-beenthere-env:x-beenthere;
b=uPPRC+W/v3zHotn2sCwTcwITD4EEUcDbeOybDWSeP6i+ZXGGyjoflcmoUi6S4Tmj4G
u+Mam61OyL76I38IXydo3PtAHwdW0lxF7pyIfFHYIHzuPhaEJE79DUS/c51bl3YG1QEC
LFNS3eI49Rc4+8QEd9of7cNx0rD3NRtU2Ln2MReceived: by 10.143.167.15 with SMTP id u15mr37747wfo.25.1228923712652;
Wed, 10 Dec 2008 07:41:52 -0800 (PST)
Received: by 10.230.24.165 with SMTP id v37gr33366vbb.0;
Wed, 10 Dec 2008 07:41:46 -0800 (PST)
X-Sender: ***@motorola.com
X-Apparently-To: android-***@googlegroups.com
Received: by 10.115.93.18 with SMTP id v18mr819449wal.13.1228923705929; Wed, 10 Dec 2008 07:41:45 -0800 (PST)
Received: from mail119.messagelabs.com (mail119.messagelabs.com [216.82.241.195]) by mx.google.com with SMTP id k32si3861511wah.1.2008.12.10.07.41.45; Wed, 10 Dec 2008 07:41:45 -0800 (PST)
Received-SPF: neutral (google.com: 216.82.241.195 is neither permitted nor denied by best guess record for domain of ***@motorola.com) client-ip!6.82.241.195;
Authentication-Results: mx.google.com; spf=neutral (google.com: 216.82.241.195 is neither permitted nor denied by best guess record for domain of ***@motorola.com) smtp.mail=***@motorola.com
X-VirusChecked: Checked
X-Env-Sender: ***@motorola.com
X-Msg-Ref: server-4.tower-119.messagelabs.com!1228923704!32516745!1
X-StarScan-Version: 6.0.0; banners=-,-,-
X-Originating-IP: [129.188.136.8]
Received: (qmail 31969 invoked from network); 10 Dec 2008 15:41:44 -0000
Received: from motgate8.mot.com (HELO motgate8.mot.com) (129.188.136.8) by server-4.tower-119.messagelabs.com with SMTP; 10 Dec 2008 15:41:44 -0000
Received: from il06exr02.mot.com (il06exr02.mot.com [129.188.137.132]) by motgate8.mot.com (8.12.11/Motorola) with ESMTP id mBAFfiKT020570 for <android-***@googlegroups.com>; Wed, 10 Dec 2008 08:41:44 -0700 (MST)
Received: from il06vts04.mot.com (il06vts04.mot.com [129.188.137.144]) by il06exr02.mot.com (8.13.1/Vontu) with SMTP id mBAFfixc010648 for <android-***@googlegroups.com>; Wed, 10 Dec 2008 09:41:44 -0600 (CST)
Received: from zmy16exm71.ds.mot.com (zmy16exm71.ap.mot.com [10.179.4.43]) by il06exr02.mot.com (8.13.1/8.13.0) with ESMTP id mBAFfgAf010634 for <android-***@googlegroups.com>; Wed, 10 Dec 2008 09:41:43 -0600 (CST)
X-MimeOLE: Produced By Microsoft Exchange V6.5
Content-class: urn:content-classes:message
In-Reply-To: <***@commonsware.com>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: [android-developers] Re: Getting error when trying to read file : java.lang.IllegalArgumentException: File /data/testing.txt contains a path separator
thread-index: Acla0rt9j6XroPNDTUOjGxiwtXH8qwACqXBA
X-CFilter-Loop: Reflected
Sender: android-***@googlegroups.com
Precedence: bulk
X-Google-Loop: groups
Mailing-List: list android-***@googlegroups.com;
contact android-developers+***@googlegroups.com
List-Id: <android-developers.googlegroups.com>
List-Post: <mailto:android-***@googlegroups.com>
List-Help: <mailto:android-developers+***@googlegroups.com>
List-Unsubscribe: <http://googlegroups.com/group/android-developers/subscribe>,
<mailto:android-developers+***@googlegroups.com>
X-BeenThere-Env: android-***@googlegroups.com
X-BeenThere: android-***@googlegroups.com
Archived-At: <http://permalink.gmane.org/gmane.comp.handhelds.android.devel/16609>


Hi Mark,

Thanks for reply, is there any methods to read non-local file (file
present outside my application specific area).

Arvind

-----Original Message-----
From: android-***@googlegroups.com
[mailto:android-***@googlegroups.com] On Behalf Of Mark Murphy
Sent: Wednesday, December 10, 2008 7:52 PM
To: android-***@googlegroups.com
Subject: [android-developers] Re: Getting error when trying to read file
: java.lang.IllegalArgumentException: File /data/testing.txt contains a
path separator
Post by Chandrakar Aravind-rqj386
java.lang.IllegalArgumentException: File /data/testing.txt
contains a path separator
You probably don't have a file at /data/testing.txt.
Post by Chandrakar Aravind-rqj386
FileInputStream _orifile_ =
openFileInput("/data//_samplefile_._txt_");
openFileInput() accepts relative paths only. No leading slashes are
allowed. openFileInput() represents files stored in an
application-specific storage area. getFilesDir() will tell you where
this is, IIRC.

--
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.9 Available!
kelly
2008-12-10 16:35:05 UTC
Permalink
You might try just using java.io.File, which works well for me:

File file = new File("/whatever/path/to/file.txt");
try {
InputStream in = new FileInputStream(file);

...
}
catch(Exception ex)
{
...
}

I've noticed in the documentation that openFileInput() is supposed to
be what you use, but I haven't determined if the above is not okay,
and if not, why not. I'm doing this in several places, and it has
never caused a problem.
Post by Chandrakar Aravind-rqj386
Hi Mark,
Thanks for reply, is there any methods to read non-local file (file
present outside my application specific area).
Arvind
-----Original Message-----
Sent: Wednesday, December 10, 2008 7:52 PM
Subject: [android-developers] Re: Getting error when trying to read file
: java.lang.IllegalArgumentException: File /data/testing.txt contains a
path separator
      java.lang.IllegalArgumentException: File /data/testing.txt
contains a path separator
You probably don't have a file at /data/testing.txt.
      FileInputStream _orifile_ =
openFileInput("/data//_samplefile_._txt_");
openFileInput() accepts relative paths only. No leading slashes are
allowed. openFileInput() represents files stored in an
application-specific storage area. getFilesDir() will tell you where
this is, IIRC.
--
Mark Murphy (a Commons Guy)http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.9 Available!
Mark Murphy
2008-12-10 16:38:33 UTC
Permalink
Post by kelly
File file = new File("/whatever/path/to/file.txt");
try {
InputStream in = new FileInputStream(file);
...
}
catch(Exception ex)
{
...
}
That works, so long as you have read access to whatever it is you're
trying to read. And, so long as you are able to put files wherever it is
you're trying to read them from.
Post by kelly
I've noticed in the documentation that openFileInput() is supposed to
be what you use, but I haven't determined if the above is not okay,
and if not, why not. I'm doing this in several places, and it has
never caused a problem.
openFileInput() gives you a storage spot unique to your application in
the on-board flash. It is not for use for, say, accessing /sdcard.
--
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.9 Available!
kelly
2008-12-10 16:56:36 UTC
Permalink
Ah, that makes sense. What I'm doing with the java.io.File approach is
reading/writing to/from areas on the sd card.
Post by Mark Murphy
Post by kelly
File file = new File("/whatever/path/to/file.txt");
try {
  InputStream in = new FileInputStream(file);
  ...
}
catch(Exception ex)
{
  ...
}
That works, so long as you have read access to whatever it is you're
trying to read. And, so long as you are able to put files wherever it is
you're trying to read them from.
Post by kelly
I've noticed in the documentation that openFileInput() is supposed to
be what you use, but I haven't determined if the above is not okay,
and if not, why not. I'm doing this in several places, and it has
never caused a problem.
openFileInput() gives you a storage spot unique to your application in
the on-board flash. It is not for use for, say, accessing /sdcard.
--
Mark Murphy (a Commons Guy)http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.9 Available!
e***@gmail.com
2008-12-10 22:34:43 UTC
Permalink
Post by Mark Murphy
openFileInput() gives you a storage spot unique to your application in
the on-board flash. It is not for use for, say, accessing /sdcard.
This brings up a question I have: is there an etiquette for apps
putting stuff on
the sdcard? If there were some app specific storage area on the sdcard like
openFileInput does on the internal memory, it would seemingly help for
namespace collisions and other untidy stuff on the sdcard...

Mike
Michael
2008-12-10 22:43:00 UTC
Permalink
I noticed that lots of apps have been making a mess of my SD card. So
when I had to store some data there, I made the decision to keep
things cleaner. The path I used is /var/MyProgramName/ and then
various directories below.

Loading...