get the file in the desired folder

Put your problem here if it does not fit any of the other categories.

get the file in the desired folder

Postby deepakpengoria » Mon Aug 11, 2008 9:49 am

hello ,

i have small problem. I can save my data into the file but that file is saved in some database. but while i want to change the location of the file n save it throws an exception.

kindly guide me how to save the files in the particular location and also retrieve it..

thanks in advance..
deepakpengoria
Junior Developer
Junior Developer
 
Posts: 11
Joined: Fri Aug 08, 2008 9:12 am

Top

Postby cgreen » Tue Aug 12, 2008 9:38 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     File mFile = new File("PATHANDNAME/TOFILE");
  2.  
  3.     mFile.createNewFile();
  4.  
  5.     FileOutputStream fout = new FileOutputStream(mFile);
  6.  
  7.     fout.write(ANYDATA);
Parsed in 0.029 seconds, using GeSHi 1.0.8.4
User avatar
cgreen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Wed Jul 16, 2008 10:16 am

Postby deepakpengoria » Tue Aug 12, 2008 12:11 pm

Thanks for reply, but it was giving an IO Exception that the file canot be created.

The code i uesd is.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.             File mFile = new File("/root/workspace/","a.txt");
  3.  
  4.             mFile.createNewFile();
  5.  
  6.             FileOutputStream fout = new FileOutputStream(mFile);
  7.  
  8.             String s=new String("hello deepak here");
  9.  
  10.             byte buf[]=s.getBytes();
  11.  
  12.             fout.write(buf);
  13.  
  14.            
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
deepakpengoria
Junior Developer
Junior Developer
 
Posts: 11
Joined: Fri Aug 08, 2008 9:12 am

Postby cgreen » Tue Aug 12, 2008 4:35 pm

try
new File("/data/data/","a.txt");
User avatar
cgreen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Wed Jul 16, 2008 10:16 am

Postby deepakpengoria » Tue Aug 12, 2008 7:49 pm

Thanks yaar,
But it is also giving the same Exception error...
plz guide.
deepakpengoria
Junior Developer
Junior Developer
 
Posts: 11
Joined: Fri Aug 08, 2008 9:12 am

Postby ych.tiger » Wed Aug 13, 2008 3:50 am

cgreen wrote:try
new File("/data/data/","a.txt");


Hi,
we can't create new file in /data/data/, since the folder's permissions is "rwxrwx--x".
if you want create new file, you must have 'w' permissions for the folder.

you can try new File("/data/download/a.txt").createNewFile();
User avatar
ych.tiger
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Jul 08, 2008 4:07 am
Location: China

Top

Postby deepakpengoria » Wed Aug 13, 2008 7:36 am

@ych.tiger

It was working. But i got another problem that what if i want to save file in desired folder such as "/root/workspace/" folder...
so wht should i do. Its giving IO Exception error.

plz giude..

Thanks in advance.
deepakpengoria
Junior Developer
Junior Developer
 
Posts: 11
Joined: Fri Aug 08, 2008 9:12 am

Postby ych.tiger » Wed Aug 13, 2008 8:00 am

deepakpengoria wrote:@ych.tiger

It was working. But i got another problem that what if i want to save file in desired folder such as "/root/workspace/" folder...
so wht should i do. Its giving IO Exception error.

plz giude..

Thanks in advance.


You can't directly to write (or new ) file in the folder that you haven't 'w' permission on it, as much as I know.
But, You can find some 'rwxrwxrwx'-folder in Android with DDMS's file explorer. these folders is free.
Your package 's folder(example /data/data/[Your Package's name]/) is also free.
User avatar
ych.tiger
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Jul 08, 2008 4:07 am
Location: China

Postby deepakpengoria » Wed Aug 13, 2008 8:10 am

Thanks for information,

can u guide me how can i save the file which contain bold, italics etc.. like format and can return the data with similar styles..

plz guide,,,
deepakpengoria
Junior Developer
Junior Developer
 
Posts: 11
Joined: Fri Aug 08, 2008 9:12 am

Postby ych.tiger » Wed Aug 13, 2008 8:22 am

deepakpengoria wrote:Thanks for information,

can u guide me how can i save the file which contain bold, italics etc.. like format and can return the data with similar styles..

plz guide,,,


Hi,

I hadn't solve the rich-text problem on Android platform.
But, you can try save Rich-Text file with xml or html.

If I(you) have a better way, will tell you(I).

Is the data dynamic or static ? There some informations about text styles in Android document.
User avatar
ych.tiger
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Jul 08, 2008 4:07 am
Location: China

Postby deepakpengoria » Wed Aug 13, 2008 9:22 am

The data is static only...ya i know some info like
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), a,b, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


is used for italics .. similarly we can use the other formats..

but its not possible to save in rich text format...

plz guide..
deepakpengoria
Junior Developer
Junior Developer
 
Posts: 11
Joined: Fri Aug 08, 2008 9:12 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 8 guests