Solved

FileReader

Posted on 2004-10-09
2
154 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 20 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

705 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