Question

File dir = new File("c:\\programming"); String newFileName = "list.txt"; Write a code that creates a new...

File dir = new File("c:\\programming");

String newFileName = "list.txt";

Write a code that creates a new file specified by newFileName in the directory specified by dir.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*************************************CreateFile.java***********************************/

import java.io.File;
import java.io.IOException;

public class CreateFile {

   public static void main(String[] args) {

       File dir = new File("c:\\programming");
       String newFileName = "list.txt";
      
       dir.mkdir();
      
       File myFile = new File(dir,newFileName);
       try {
           myFile.createNewFile();
       } catch (IOException e) {
           e.printStackTrace();
       }
  
  
      
   }
}
/***************output***********************/

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
File dir = new File("c:\\programming"); String newFileName = "list.txt"; Write a code that creates a new...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a socket network programming in C++ or C (please write your source code) Requirement :...

    write a socket network programming in C++ or C (please write your source code) Requirement : Basic : implement a client and a server similiar with ftp protocol, complete the basic function of file transfer. - list the files/ directories -change working-directory -download file/s -Upload files/s

  • Java Programming Write a function which is passed two strings. The function creates a new string...

    Java Programming Write a function which is passed two strings. The function creates a new string from two original strings by copying one character from each in turn until all characters have been copied. No use of scanner, hashmap, or exceptions please.

  • The function dir() (same as the list.files function) can be used to list files in a...

    The function dir() (same as the list.files function) can be used to list files in a directory. Read the help file on the dir() function. Write code that will allow you to list the files in a directory and all subdirectories. Include the code in your answer.

  • 1) Which sed command line string will delete any line that begins with the string 'directory'...

    1) Which sed command line string will delete any line that begins with the string 'directory' within the file called sedfile. A) sed '/dir/d' sedfile B) sed '/^dir/d' sedfile C) sed 's/^dir/d' sedfile D) sed '/directory/d' sedfile 2) Complete the sed commmand string below. Create a sed command line string that will replace ALL the occurrences of X and x with s within the file called sedfile. sed 's/##/s/g' sedfile Replace the ## with the BEST correct answer. A) [X,x]...

  • This is for C Programming Write a function that checks whether a given string is a...

    This is for C Programming Write a function that checks whether a given string is a palindrome or not, recursively. Palindrome is a word, phrase, or sequence that reads the same backward as forward. You may not modify the functions signatures, that is, adding any new parameters or changing the data type of the parameters in any way. You may not use square brackets and any type of loops in your solutions. For example: isPalindrome("abcba", ...) -> true isPalindrome("abcb1", ...)...

  • 8. Write few lines of code that creates two arrays with malloc. Then write a statement...

    8. Write few lines of code that creates two arrays with malloc. Then write a statement that can create a memory leak. Discuss why you think your code has a memory leak by drawing the status of the memory after you use malloc and the line of the code you claim that creates a memory leak. (C Programming)

  • You are working with the file directory of a Windows XP computer from the command line,...

    You are working with the file directory of a Windows XP computer from the command line, and you use the md command to create a new directory in your My Documents directory. What command switch can you issue to confirm that the new directory was created? A. Just use the dir command to view all of the directories and files in the My Documents and look for the name of directory you just created B. dir /new C. dir /bn...

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to...

    File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to successfully complete chapter 9 programming exercise #3. File Encryption and Decryption Write a program that uses a dictionary to assign “codes” to each letter of the alphabet. For example: codes = { ‘A’ : ‘%’, ‘a’ : ‘9’, ‘B’ : ‘@’, ‘b’ : ‘#’, etc . . .} Using this example, the letter A would be assigned the symbol %, the letter a would...

  • USING PYTHON PROGRAMMING LANGUAGE 15. Write code to open a file named data.txt, which contains 3...

    USING PYTHON PROGRAMMING LANGUAGE 15. Write code to open a file named data.txt, which contains 3 numbers, and print the sum of those numbers to the console 16. Write code that opens a file named words.txt containing an essay, and the prints out the SECOND word in the file to the console

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT