Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

FileReader

Posted on 2004-10-09
2
Medium Priority
?
157 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

610 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