creating a file in a directory

creating a file in a directory

hi i have tried all the file methods to create a file inside a directory but none of them r working some of them are

new File ( ".", "C:/fileInRoot.txt" ) new File ( "myDir", "/otherDir" ) File( "myDir/OtherDir" ) File( "/OtherDir" ); new File ( "species/clan/individual.txt" )

can anyone help me

View Answers

February 14, 2011 at 1:00 PM

Java Create File

import java.io.*;

public class CreateFile{
    public static void main(String[] args) throws IOException{
      File f;
      f=new File("C:/myfile.txt");
      if(!f.exists()){
      f.createNewFile();
      System.out.println("New file has been created inside the C folder);
      }
    }
}

March 7, 2012 at 1:30 PM

package com.lara; import java.io.File; import java.io.IOException;

public class G { public static void main(String[] args) { File f1 = new File("E:/Notes/pqr.txt"); System.out.println(f1.exists());

 try
 {
     boolean b = f1.createNewFile();
 }
 catch(Exception ex)
 {
     System.out.println(ex);
 }

} }









Related Tutorials/Questions & Answers:
creating a file in a directory
creating a file in a directory  hi i have tried all the file methods to create a file inside a directory but none of them r working some of them are new File ( ".", "C:/fileInRoot.txt" ) new File ( "myDir", "/otherDir" ) File
Creating a File in the directory.
Creating a file using HTML form action In this example, you will learn to make a query form asking to to create a file in PHP. You will have to write... of PHP code in the form.ADS_TO_REPLACE_1 for creating a file in PHP, first
Advertisements
Creating a setup file
Creating a setup file  How to create a setup file in tomcat as done in visual studio... could plz tell me as early as possible
Creating XMl file - XML
Creating XMl file   I went on this page: http://www.roseindia.net/xml/dom/createblankdomdocument.shtml and it shows me how to create an XML file, however there is something I don't understand. I have to create an XML file
Creating an executable jar file
Creating an executable jar file  When I try to create jar.exe through CMD, the manifest file created doesn't contain Main-Class attribute, even though it is included in text file used during creation of jar file
Creating an exe file
Creating an exe file  Hi All, I have developed java application using swing by Net Beans IDE. Now I need to convert my application into exe file... as an exe file. Please anyone suggest me.Thanks in Advance. Thanks, T.Thanga meena
creating a jar file - JSP-Servlet
creating a jar file  Can you give me detail answer 1. i am having a servlet.class file in classes folder 2. web.xml file my questions are 1. where to place the html or jsp files 2. how to create a jar file and how can
creating an .exe file - Java Beginners
creating an .exe file  how to create an .exe file in java? thanks in advance
a jsp code for creating a text file
a jsp code for creating a text file  Hello,i need jsp code for creating a new text file for each user, when they login in to the website for creating a new data file. So i need a jsp code for following options. when user login
Creating JAR File - Java Beginners
Creating JAR File  Respected Sir, Thankyou very much for your... to change the contents of my manifest file. I read somewhere regarding i have to add a line to my manifest file (i.e. Main-Class: mypackage.MyClass
Creating JAR File - Java Beginners
Creating JAR File  Respected Sir, I would like you to please help me, in letting me know, as to how to create JAR file from my JAVA source or class files. And what is this manifest file, and what changes needs to be done
Creating a log in a text file - Applet
Creating a log in a text file  Hey there, I have created an applet... as an application. Therefore i have added it onto a frame. I need to create a text file... time it is run. I have figured of a way of writing the time to a text file using
File Directory Merging
File Directory Merging  Two directories are given. Both contain a large amount of files. Each of the directory can be more than a GB. We need to form a new directory in which all the files from both the directories
How to move a file from a directory to other directory
How to move a file from a directory to other directory  I tried the above example it will move the folder to other directory but it does not move the image file or other file to a specified directory. Can anyone help me? Thanks
Creating dynamic jsp file in java file to include another jsp file
Creating dynamic jsp file in java file to include another jsp file  I am able to create jsp file in java that includes ; table tr td and img tags..... Need to include jsp file in the same content. The below code doesn't help me
Traversing a file and directory under a directory
then make an object of File class and pass any directory and filename to its constructor. After that, check it whether the file or directory you have entered is a directory or a file. If it is a directory then it will display
Creating a JAR file in Java
Creating a JAR file in Java       This section provides you to the creating a jar file.... This program has been used the jar command "jar cf jar-file-name directory
ls: cannot access >: No such file or directory
/f.txt from terminal in linux its creating f.txt.But cant run from java program ls: cannot access >: No such file or directory error is displayed .No f.txt...ls: cannot access >: No such file or directory  import
Delete file or Directory
Delete file or Directory      ... or a directory by using a java program. We pass the file name or the directory name to which... are creating a delete() method. In this method first we are creating a file object
Java - Deleting the file or Directory
of file and directory pathnames. ADS_TO_REPLACE_1 Explanation...() which deletes the specified directory or file. deletefile(String file)ADS...() Deletes the file or directory denoted by this abstract pathname
Checking if a file or directory exist
Checking if a file or directory exist In this section you will learn how to check whether a file or a directory exist or not. The " java.io "... will return "true" if file or directory exist otherwise it returns "
creating new file with File class - JSP-Interview Questions
creating new file with File class   I have a file uploading concept in my project. For that, while creating a new file is it necessary to give... of FileOutputStream class. If we give the path as from the file uploading location will it work
Moving file or directory from one directory to another
Moving file or directory from one directory to another... illustrates you the method or procedure for moving a file or directory contents... contents of the mention file or directory as a source directory
Copy Directory or File in Java
will see how contains of a directory or a file is copied  from... then the program gives the output message like : File or directory does not exist... to the destination directory otherwise the specified name is copies (treated) as a file name
Java - Deleting the file or Directory
Java - Deleting the file or Directory   ... the specified file or directory after checking weather the file exists or not. This topic... representation of file and directory pathnames. ADS_TO_REPLACE_1 Explanation
Create text file at client's directory from server.
Create text file at client's directory from server.  Need java code to create text file at client's directory from server..... Please Help
Determining if a File or Directory exist
Determining if a File or Directory Exist   ... to determine whether a file or directory exists or not. If it exists it ... whether the file or directory denoted by this pathname exists or not. Here
Rename the File or Directory in Java
Rename the File or Directory in Java   ... that how a file or directory is renamed. This program illustrates you the procedure... or directory. If you mention the directory (path) with the new file or directory
Java file get parent directory
Java file get parent directory In this section, you will learn how to get the parent directory of the file. Description of code: The package java.io.... which of String type. This method returns the parent directory of specified file
File copy from one directory to another in java
File copy from one directory to another in java  I am trying to find very good code example for copying a file from one directory to another directory in Java. I have to write a program in my application for copying one file
problem in creating create .ipa file in my iPhone app
problem in creating create .ipa file in my iPhone app  Hi, does anyone have idea on how to create a .create .ipa file for my iPhone / iPad application? Also do i need to delete the previous build to create .ipa file? Thanks
Creating a File I/O using import scanner, io.* and text.*
Creating a File I/O using import scanner, io.* and text.*  open a file for reading and open another file for writing data. input file hours-int, hourly rate-double, name-string. output file name-string, hours-int, hourly rate
Creating objects for classes and calling functions of a dll file using JNI
Creating objects for classes and calling functions of a dll file using JNI  Hi all, I am new to JNI. I am having a dll file created by somebody else. In this file, some c++ classes and functions are available. How can we create
Directory and File Listing Example in Java
C:\nisha>java DirListing example myfile.txt C:\nisha> At the time of execution, we have specified a directory name "example" that contains only a single file
Determining if a Filename path is a file or a directory
Determining if a Filename path is a file or a directory..._TO_REPLACE_1 isDirectory(): It checks whether the file is a directory or not. getAbsolutePath(): It returns the absolute path of a file or directory. Code
How to load file from the directory in J2ME?
How to load file from the directory in J2ME?  Video player J2ME. I have a folder name "music". I want to display all file with extension is "*.mpg" on the List. How can I do it, plz help me
Error: /usr/sbin/ifconfig: No such file or directory
Error: /usr/sbin/ifconfig: No such file or directory  HI, I am trying to run the some setup and it throws the error: Error: /usr/sbin/ifconfig: No such file or directory How to solve this? Thanks   HI, this error
URL file Download and Save in the Local Directory
URL file Download and Save in the Local Directory   ... and save this Url File in the specified directory. This program specifies... and FileOutputStream write the data to the local file in a specified directory
how to copy file from one directory to another in java with examples
how to copy file from one directory to another in java with examples  how to copy file from one directory to another in java with examples? I want a java with example code Thanks   Hi, Please check the thread File
Creating a properties file
Creating a Properties File      This file is used for the purpose of storing some key and value pairs... with the value of the key. The other benefit of using this file is that we can change
ModuleNotFoundError: No module named 'odoo10-addon-base-directory-file-download'
ModuleNotFoundError: No module named 'odoo10-addon-base-directory-file-download...: ModuleNotFoundError: No module named 'odoo10-addon-base-directory-file-download...-directory-file-download' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo10-addon-base-directory-file-download'
ModuleNotFoundError: No module named 'odoo10-addon-base-directory-file-download...: ModuleNotFoundError: No module named 'odoo10-addon-base-directory-file-download...-directory-file-download' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo11-addon-base-directory-file-download'
ModuleNotFoundError: No module named 'odoo11-addon-base-directory-file-download...: ModuleNotFoundError: No module named 'odoo11-addon-base-directory-file-download...-directory-file-download' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo11-addon-base-directory-file-download'
ModuleNotFoundError: No module named 'odoo11-addon-base-directory-file-download...: ModuleNotFoundError: No module named 'odoo11-addon-base-directory-file-download...-directory-file-download' error? Thanks   Hi, In your python
Creating a ZIP file in Java
Creating a ZIP file in Java       Zip File: Zip file format is the popular method of data compression. Zip file contains many files in compressed format. You can
Create a new zip file in ZipArchive.
Creating a new Zip file in ZipArchive For creating zip file, use zipArchive () class. Create a new zip file in ZipArchive. Use the conditional statement... will generate a new zip file, in case of failure, it will print failed in creating
Create a directory in php
Creating a directory in php In  this example, you will learn to create a form in HTML and call php action function of creating directory in HTML form... in the form to create a directory. In PHP, you can create a directory using mkdir
Creating a temporary file
Java Temporary File - Temporary File Creation in Java... a temporary file, which will be deleted automatically by the garbage collector when... createTempFile(String prefix, String suffix): This is a static method of file
Java file new directory
Java file new directory In this section, you will learn how to create a new directory. Description of code: This is a common task. The java.io.package... have created an object of File class and specify a directory which you want
How to import data from sql server table into an excel file by creating the rows dynamically in the excel according to the dataabase??
How to import data from sql server table into an excel file by creating... data from sql server table into an excel file by creating the rows dynamically... to create an excel file according to that and keep updating the same

Ads