in JAVA, why my code can run, but it does not show any files on my desktop.
Scanner k = new Scanner(System.in);
System.out.println(" Please enter the first filename: ");
String fileName1 = k.nextLine();
System.out.println(" Please enter the second filename: ");
String fileName2 = k.nextLine();
File f1 = new File(fileName1);
Scanner file1 = new Scanner(f1);
PrintWriter f2 = new PrintWriter(fileName2);
while(file1.hasNext()){
String str= fileName1.toUpperCase();
f2.println(str.toUpperCase());
}
file1.close();
f2.close();
}
I made some changes and succefully it is showing all the files on desktop.You can see the changes in following code
import java.util.*;
import java.io.*;
class FileDemo
{
public static void main(String args[])
{
try
{
Scanner k = new Scanner(System.in);
System.out.println(" Please enter the first filename: ");
String fileName1 = k.nextLine();
System.out.println(" Please enter the second filename: ");
String fileName2 = k.nextLine();
PrintWriter f1 = new PrintWriter(new File(fileName1));
PrintWriter f2=new PrintWriter(new File(fileName2));
Scanner file1=new Scanner(new File(fileName1));
String str;
while(file1.hasNext())
{
str= fileName1.toUpperCase();
f2.println(str.toUpperCase());
}
f1.close();
f2.close();
}
catch(Exception e1)
{
System.out.println(e1);
}
}
}
in JAVA, why my code can run, but it does not show any files on my...
**Java** Assume that indata1 and indata2 are two files containing at least two integers, separated by white space. Write a program named Add2 that writes the sum of the first integers of these two files to a file named outdata1. It writes the sum of the first integers of these two files to a file named outdata2. Each sum is written on a line by itself. So, if the contents of indata1 were "37 6 90" and the contents of...
Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class Car { private int year; private String model; private String make; int speed; public Car(int year, String model, String make, int speed) { this.year = year; this.model = model; this.make = make; this.speed = speed; } public Car() { } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getModel() { return model; }...
Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20 import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; public class Main1 { private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0; public static...
i have to write a program that asks the names of 2 files. the first should be open for reading second for writing. the program should read the the contents of the first file change all characters to uppercase and store in the second file. the second file will be a copy of the first file, except that all characters will be uppercase. use notepad to test the program. i got this so far { String firstfile; String...
JAVA Which of these statements does not match by using exception action in Java? 1. Exception action makes it possible for the calling method to handle errors in called methods. 2. Exception action simplifies programming since incorrect reporting and handling can be located in catch blocks separately from the rest of the code. 3. Exception action increases the performance of programs. 4. Java separates exception action from common processes. Why create instances of File Class? - several alternatives...
Q22 Consider the following 2 text files and Java program. 8 Points Answer the following questions keeping in mind that: • All three files are in the same directory, and there are no other files. • The program may crash. If the program crashes, answer the question with: "The program crashes" standings1.txt: 1 Valtteri Bottas 25 2 Charles Leclerc 18 3 Lando Norris 16 4 Lewis Hamilton 12 standings2.txt: 1 Valtteri Bottas 43 2 Lewis Hamilton 37 3 Lando Norris...
In JAVA, In two classes: As a zookeeper, it is important to know the activities of the animals in your care and to monitor their living habitats. Create a monitoring system that does all of the following: -Asks a user if they want to monitor an animal, monitor a habitat, or exit -Displays a list of animal/habitat options (based on the previous selection) as read from either the animals or habitats file and asks the user to enter one of...
Can anyone help me? Thank you very much. Question 10 1 pts The constructor below is very similar to the one you used for the last assignment. What is its time complexity in terms of N, where N is the number of lines in the Input Stream (the word file)? public Doublets (Inputstream in) try t lexicon. new TreeSet String O; Scanner s new Scanner (new BufferedReader new I (in))) while (s hasNext String str s next boolean added lexicon....
The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { public static void main(String args[]) { int num; int num2; Scanner input = new Scanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number ");...
JAVA Code: Complete the program that reads from a text file and counts the occurrence of each letter of the English alphabet. The given code already opens a specified text file and reads in the text one line at a time to a temporary String. Your task is to go through that String and count the occurrence of the letters and then print out the final tally of each letter (i.e., how many 'a's?, how many 'b's?, etc.) You can...