• Post Reply Bookmark Topic Watch Topic
  • New Topic

File Creation Problem in unix  RSS feed

 
sai sekhar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my code i am trying to write a file to the directory /home/bdb/store/

and i am creating a

File f = new File("/home/dbd/store/"+filename);
and giving it Outputstream ..

but when i say
private static String STOREDIR ="/home/bdb/store/";

File f = new File(STOREDIR,filename); i getting FileNotFoundException
please can somebody show me the right way to give file paths in unix so that i can read and write to that directory
[ January 18, 2006: Message edited by: sai sekhar ]
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15862
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In one line, you are talking about bdb.
In another line, you are talking about dbd.

Which one is right, bdb or dbd?
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ja ja Sounds like one of those cases for eXtreme Programming. It happens to us all, from time to time.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15862
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You sent me a private message. Why didn't you just post a reply here, so that other people can help you with the problem too?

Here's what you wrote in the private message:
hi, can you help me out i need to read/write a file in unix system , my
requirement is i should be able to createa directory , if it is not existing and
write the file there.
and also should be able to read from the directory ..

if i am hardcoding the path it is writing the file, which i donnot want ..

You can create a directory by using the method mkdir() or mkdirs() in class java.io.File. Look those methods up in the API documentation, that explains exactly how to use them.
 
sai sekhar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
people i tried using mkdir() also but it is creating the file only once and second time with different filename , it is not writing the file, so i am semding you the code you can look at it and then tell me

try {

File f = new File("/home/dbd/store");
if(f.isDirectory()){
f.mkdir();
}
File file1 = new File(f,filename)
outputfile = new FileOutputStream(file1);
....
}catch(Exception e){}
[ January 18, 2006: Message edited by: sai sekhar ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!