?
Solved

FileReader

Posted on 2004-10-09
2
Medium Priority
?
155 Views
Last Modified: 2010-03-31
How can I do smth like......try to open a file, and if the file does not exist, create one with the following line:

admin:admin

?

Apparently, I can only try to open the file but it reports exception if the file doesnt exist.
0
Comment
Question by:jtcy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 80 total points
ID: 12266356
File  createFile(String str)
{
           File file=new File(str);
            if(file.exists() )
           {
                      return file;
             }
            else
           {
                      FileOutputStream fout=new FileOutputStream(file);
                      fout.write("admin:admin".getBytes());
                       fout.close();
                       return new File(str);
            }
           
}
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12266391
you can call like this

createFile("admin.txt");


if admin.txt dows not exists it creates and dumps "admin:admin" into the file
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question