creating a file in a directory

Ads
 

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);
 }

} }

Ads









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 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
Advertisements
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
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
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
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
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
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...() method. In this method first we are creating a file object that contains the file
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 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
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
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
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
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
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
reading multiple files from a directory and writing them into a single file
reading multiple files from a directory and writing them into a single file... file i get an empty text file can you guide me how to do this: /*this program reads multiple files * from a single directory. */ package elite.tech.com
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
Create Temp File
of program will help you in creating a Temporary File to your default directory. Here... is created to the default directory.  A temporary file is a file that is created... Create Temp File     
Java search text file
file in the current directory. For this, we have prompt the user to enter..., display an error message. Then search the file in the current directory. If the file does not exist in the current directory then also display an error
Java Create Directory
The following example will show how to Create Directory in Java. Though this can be created by using mkdir() also, the following program has used file object in File class. 'try' and 'catch' are used for exception during execution
creating index for xml files - XML
creating index for xml files  I would like to create an index file for xml files which exist in some directory. Say, my xml file is like below... flow will be like below: for (every xml file in directory) { for (every
Java Create Directory Example
, to many directories in directory you need to call the mkdirs() mehtod. An example of creating a directory in java is given below SampleInterfaceImp.java import...Java Create Directory Example To create a directory in java call the mkdir
Creating a Web Application with the JSF Framework
illustrates how to add JSF supporting file while creating a new web application... Creating a Web Application with the JSF Framework... by just pressing the ctrl+1 button. If you expand the Configuration file you will see

Ads