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 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...
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...
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
Using for loops: - write a Java program that adds numbers between 1 to 100 and...
Using for loops: - write a Java program that adds numbers between 1 to 100 and prints the result. - write a Java program that adds odd numbers between 1 to 100 and prints the result - write a Java program that averages even numbers between 5 to 30 and prints the result
Part 1 Write a program where a child is created to execute command that tells you...
Part 1 Write a program where a child is created to execute command that tells you the date and time in Unix. Use ​execl(...)​. Note: you need to specify the full path of the file name that gives you date and time information. Announce the successful forking of child process by displaying its PID. Part 2 Write a program where a child is created to execute a command that shows all files (including hidden files) in a directory with information...
JAVA Write a program that has two functions in which the user chooses which one to...
JAVA Write a program that has two functions in which the user chooses which one to perform; 1. reads in a CSV file of integers into an array and insert it into a binary search tree class 2. deserializes an object and inserts it into a binary search tree class the tree class must be in a separate class from the CSV file read and deserialize object load
Write a Java program that reads words from a text file and displays all the words...
Write a Java program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. 1. You must use one of following Concrete class to store data from the input.txt file. Vector, Stack, ArrayList, LinkedList 2. To sort those words, you should use one of existing interface methods available in Collection or List class.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT