CIS355 Q7 Complete Solution
For Project 1: Using any java compiler complete the following 6 questions below:
Ensure that you write java code for each question
Project I: Using DOS Commands with Java
1. Create two files called: File1.txt and File2.txt
Print Screen below here and copy and paste code:
Here is the code:
import java.util.Formatter;
import javax.swing.JOptionPane;
public class Files
{
public static void main(String[] args)
{
final Formatter x, h;
try
{
x = new Formatter("File1.txt");
h = new Formatter("File2.txt");
JOptionPane.showMessageDialog(null, "The following file " + x + "has been created");
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "Error the file has not been created" + ex);
}
}
}
2. Create a new Folder called: Folder1
Print Screen below here and copy and paste code:
Folder1 has been created in C:\\
Here is the code:
import java.io.File;
public class NewDirectory
{
public static void main(String[] args)
{
File file1 = new File("C:\\Folder1");
if(!file1.exists())
{
if(file1.mkdir())
{
System.out.println("Directory is created!");
}
else
{
System.out.println("Failed to create the directory");
}
}
}
}
3. Move #1 (2 files) into Folder1 using the Move command
Print Screen below here and copy and paste code:
4. Create another folder called Folder2
Print Screen below here and copy and paste code:
Here is the code:
import java.io.File;
public class Directory2
{
public static void main(String[] args)
{
File file1 = new File("C:\\Folder2");
if(!file1.exists())
{
if(file1.mkdir())
{
System.out.println("Folder 2 is created!");
}
else
{
System.out.println("Failed to create Folder 2");
}
}
}
}
5. Cut file1.txt into Folder2
Print Screen below here and copy and paste code:
6. Delete file1.txt from Folder2
Print Screen below here and copy and paste code:
CIS355 Q7 Complete Solution
This Tutorial is rated A+ p...
A+ - Thank you!
Thanks for the positive feedback!