Hey,
I am trying to make a program that would first read a text file or a excel file and store two types of data, a line start and a line width. I than want the program to scan a new text file and using the data it stored from the other files to store the data. An example, like the file has line start of 5 and width of 4 I want the program to then go into the other text file and go to line 5 then copy everything from line 5 to line 9. Then once it copes all the data what was listed from the first file, I want it to create an output of all the data that it copied.
My question is, how can I go about making the program copy the content at line 5 to line 9, even if it is a space?
As of right now, I have some old program I used to analyze data that would scan the first 49 numbers and do some calc.
here is the class from the old code that I want to modify. My idea was to change it so that it would store the first text file or excel file into a hash table where the key would be line start and and data would the the width. Than it would scan the other file and spit out an output in a text file or something.
I have not done java programming in a year so I am a little rusty lol
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Hashtable; import java.util.Scanner; public class data { static Scanner x; double[] data = new double[50]; double sum; public static Hashtable h = new Hashtable(); String file = "Data.txt"; int key = 1; double xaxis; double yaxis; //setter public data(double yyaxis){ this.yaxis=yyaxis; } //opens the data file public void open(){ try{ x = new Scanner(new File("C:/Users/chris/Desktop/data.txt")); } catch(Exception e){ System.out.print("no file"); } } public void read() { //reads the data in the text file and sets it to an array. while(x.hasNext()){ for(int i=1; i<=49; i++){ if(x.hasNextDouble() == false){ System.out.println("error in data"); System.exit(0); } data[i] = x.nextDouble(); // Calculates the average for every 49 set of data. //Stores that average to a hashtable if(i == 49){ sum = 0; for (int ii = 1; ii<=49; ii++){ sum = data[ii] + sum; } sum = sum / 49; data av = new data(sum); h.put(key, av.getHash()); key++; } } } //test to see the data its using to calculate System.out.printf("the average is " + sum + "size "+ h.size() + " ave " + h.get(995) + " " + h.get(996)+ " data used for average: " ); } // wrights the data to a external text file public void wright(){ try { PrintWriter outputStream = new PrintWriter(file); for(int i=1; i<=49; i++){ System.out.print(" "+data[i] + " "); outputStream.print (" " + data[i] + " "); } outputStream.println(""); outputStream.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } } //getter for hashtable public double getHash(){ return this.yaxis; } }