HiddenSquid HiddenSquid - 11 months ago 53
Java Question

using Java arraylist for storing data from scan from file

I am new to java, but not coding. I am trying to figure out java because it's part of my class this term and I am having a really hard problem grasping the idea of it and implementing things in java.

my problem Is that I am not sure if I am correctly using the arraylist to grab data from the scan of the file and input it into a arraylist to sort and print at a later time. I am just having issues picking up on java any help would be great since I am new to java.

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.*;
public class MissionCount
private static ArrayList<String> list = new ArrayList<String>();
// returns an InputStream that gets data from the named file
private static InputStream getFileInputStream(String fileName) throws Exception
InputStream inputStream;

try {
inputStream = new FileInputStream(new File(fileName));
catch (FileNotFoundException e) { // no file with this name exists
inputStream = null;
throw new Exception("unable to open the file -- " + e.getMessage());
return inputStream;

public static void main(String[] args) {

if (args.length != 1) {
System.out.println("USage: MissionCount <datafile>");

try {
System.out.printf("CS261 - MissionCount - Chad Dreher%n%n");
int crewcount = 0;
int misscount = 0;
InputStream log = getFileInputStream(args[0]);
Scanner sc = new Scanner(log);

while (sc.hasNext())
String crewMember = sc.next();
String mission = sc.next();



// Add code to print the report here

}catch (Exception e) {
System.out.println("Error: " + e.getMessage());

InputStream log = getFileInputStream(args[0]);

Change that line to as follows :-

File log = new File(args[0])

that should work!