Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading file in Android

 
ritesh jaswal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am developing an android application.
I am trying to read a XML configuration file which is placed in SRC folder of prjoject.
But I am getting java.io.FileNotFoundException: /src/testmapping.xml (No such file or directory) exception.

Code for the same is :
File file = new File("src\\action-mapping.xml");
FileInputStream fileOutputStream;
try {
fileOutputStream = new FileInputStream(file);
//rest of the code....

However I can successfully run the same code in Java project.

Please help.
 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, the src directory is only on your development machine. Thus your code would not work anywhere except on your machine.
Second, Android doesn't use back slashes as path separators.
Third, to see the proper way to do this, read the tip at the end of this second of the documentation:
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
 
akon mask
Greenhorn
Posts: 5
Google Web Toolkit IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SRC link has work on the development machine, And you getting the link "java.io.FileNotFoundException: /src/testmapping.xml", in which an Android application can't support it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic