Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have been trying to get my code for this working for days and I can\'t get it

ID: 3560873 • Letter: I

Question

I have been trying to get my code for this working for days and I can't get it to work. I even tried posting the code i had written for it to see if someone could figure out where I had gone wrong but no luck. So if somebody could get a working version of this going I would be very grateful.

Write a program that reads a file name from the keyboard. The file contains integers, each on a separate line. The first line of the input file will contain the number of integers in the file. You then create a corresponding array and fill the array with integers from the remaining lines. If the input file does not exist, give an appropriate error message and terminate the program. After integers are stored in an array, your program should call the following methods in order, output the intermediate results and count statistics on screen, and at end output even integers and odd integers to two different files called even.out and odd.out.

Implement the following methods in the program:

public static int[] inputData()

Explanation / Answer

import java.io.*; import java.util.*; public class CopyFile { public static void main(String[] args) { String s = " "; StringBuilder sb = new StringBuilder(s); Scanner keyboard = new Scanner(System.in); System.out.println("enter directory path of the file to be pasted:"); String dirName = keyboard.next(); System.out.println("enter file name of the file to be copied"); String fileName = keyboard.next(); try { File input = new File(dirName, fileName); Scanner ind = new Scanner(input); BufferedReader in = new BufferedReader(new FileReader(input)); String str; try { while(ind.hasNextLine()) { str = in.readLine(); sb.append(str+" "); } in.close(); ind.close(); } catch(IOException e) { System.out.println("IOException"); } System.out.println("path of file to be pasted"); String dir = keyboard.next(); File myDir = new File(dir); if(!myDir.exists()) { myDir.mkdir(); } System.out.println("enter name of the file to be pasted"); String mfile; mfile = keyboard.next(); try { File myFile = new File(myDir, mfile); PrintWriter pw = new PrintWriter(new FileWriter(myFile)); String nstr; nstr = sb.toString(); char[] n = nstr.toCharArray(); for(int d = 0;d
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote