Question

Develop an Algorithm and java program using Design Recipe: 1) Develop a java program to the...

Develop an Algorithm and java program using Design Recipe:

1) Develop a java program to the content of one file to another. Hint 1: read() Hint 2: write()

2) Develop a java program to List all files in a given directory. Hint: list()

Homework Answers

Answer #1

1.

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

public class FileCopyExample {

public static void main(String[] args) {

try {

FileReader fr = new FileReader("input.txt");

BufferedReader br = new BufferedReader(fr);

FileWriter fw = new FileWriter("output.txt", true);

String s;

while ((s = br.readLine()) != null) { // read a line

fw.write(s); // write to output file

fw.flush();

}

br.close();

fw.close();

System.out.println("file copied");

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

2.

import java.io.File;

class Main {

public static void main(String[] args) {

// creates a file object

File file = new File("C:\\Users\\Guest User\\Desktop\\Java File\\List Method");

// returns an array of all files

String[] fileList = file.list();

for(String str : fileList) {

System.out.println(str);

}

}

}

Know the answer?
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
Similar Questions
1.      Create 100 text files automatically; in each file write a random number from 1 to 10....
1.      Create 100 text files automatically; in each file write a random number from 1 to 10. Use outputstreams (fileoutputstream, buffredwriter….) 2.      Read the content of the 100 files and combine them into a 1 single file. 3.      Write java code to do the following: a.      To write the following text into a text file EEEESAAA@23SDCFSAWERF%WASDFGHWERTRQW b.      Read the file using a java program c.      Find how many D’s in the file d.      Extract the text between the @ and the # 1. Create 100 text files...
Write a python program to list all files in the given directory along with their length...
Write a python program to list all files in the given directory along with their length and last modification time. The output should contain one line for each file containing filename, length and modification date separated by tabs. https://www.tutorialspoint.com/python/python_modules.htm
Write the algorithm for this program using the C++ language (not python or java). The explanation...
Write the algorithm for this program using the C++ language (not python or java). The explanation needs to be at least 250 words. Explain everything throughly step by step. While there is a built-in pop_back function in the vector class, there is no built-in pop_front function. Suppose a program needs a pop_front function that will remove the first element from the vector. For example, if the original vector is [1, 2, 3, 4, 5], then after passing in this vector...
● Write code to read the content of the text file input.txt using JAVA. For each...
● Write code to read the content of the text file input.txt using JAVA. For each line in input.txt, write a new line in the new text file output.txt that computes the answer to some operation on a list of numbers. ● If the input.txt has the following: Min: 1,2,3,5,6 Max: 1,2,3,5,6 Avg: 1,2,3,5,6 Your program should generate output.txt as follows: The min of [1, 2, 3, 5, 6] is 1. The max of [1, 2, 3, 5, 6] is...
Program using java !! Create two files, file1.csv and file2.csv Write the following information in file1.csv:...
Program using java !! Create two files, file1.csv and file2.csv Write the following information in file1.csv: Apple 1.69 001 Banana 1.39 002 Write the following information in file2.csv: Apple 1.69 001 Carrot 1.09 003 Beef 6.99 004 You have two files, both of the two files have some information about products: • Read these two files, find out which products exist in both files, and then save these products in a new file. You can use the two files you...
Need this program in Java Develop (using C++ or Java language) the software application described below....
Need this program in Java Develop (using C++ or Java language) the software application described below. Write a program that prints the day number of the year, given the date is in the form month-day-year. For example, if the input is 1-1-09, the day number is 1; if the input is 12-25-09, the day number is 359. The program should check for a leap year. A year is a leap year if it is divisible by 4 but not divisible...
Write an iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse in...
Write an iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse in O(N) time. You can use as much extra space as you need. The original list pointers CAN NOT BE MODIFIED. State in big-O notation how much extra space is used by this algorithm. Write another iterative algorithm in Java-like pseudocode for printing a singly linked list in reverse using O(1) extra space. The original list pointers CAN NOT BE MODIFIED. This algorithm can have...
Write a Java Program, that opens the file "students.txt" The program must read the file line...
Write a Java Program, that opens the file "students.txt" The program must read the file line by line The program parses each line that it reads For example, for this line: 1:mohamed:ali:0504123456:cs102:cs202 The program must print    >ID = 1    >First Name = Mohamed   >Last Name = Ali   >Mobie = 0504123456   >Courses = cs102, cs202 In addition, it adds the mobile phone number into an ArrayList called studentPhoneList Print the content and the size of studentPhoneList Show your results and provide...
UNSORTED VERSION: Write a Java program that uses “brute force” to find the closest pair, given...
UNSORTED VERSION: Write a Java program that uses “brute force” to find the closest pair, given N distinct integer points in 1-dimension. That is, all points are integers on the x-axis, and are in an array. This algorithm should go through all pairs (without sorting the elements of the array), one pair at a time, to find the current closest pair. For example, assume we had the following integers: 4, 2, -2, -1 in an array. We would then generate...
Consider the following list contained in file named input.txt: using java program Khaled 65 78 56...
Consider the following list contained in file named input.txt: using java program Khaled 65 78 56 89 -999 Kamal 37 55 44 22 18 56 26 -999 Ali 66 33 87 66 87 25 39 78 -999 Taher 12 67 -999 Write a program to read this information and Output the name and sum for each person. Note: the number of rows may vary. Assum -999 as sentenital value
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT