Solved

FileReader

Posted on 2004-10-09
2
149 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bigHeights  challenge 13 56
noX challenge 17 77
best (free) software to access postgres db (java) 1 18
@SBGen Method 3 25
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now