Question: I'm looking for some security vulnerabilities in this simple Java program that will read a .txt file named EmailAddresses.txt, read each line, and print them
I'm looking for some security vulnerabilities in this simple Java program that will read a .txt file named EmailAddresses.txt, read each line, and print them back to the console.
the code:
/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license */ package com.mycompany.sdev425_1_carnahan_joshua; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; /** * * @author jim */ public class SDEV425_1_Carnahan_Joshua { /** * @param args the command line arguments */ public static void main(String[] args) { // Read the filename from the command line argument String filename = args[0]; BufferedReader inputStream = null; String fileLine; try { inputStream = new BufferedReader(new FileReader(filename)); System.out.println("Email Addresses:"); // Read one Line using BufferedReader while ((fileLine = inputStream.readLine()) != null) { System.out.println(fileLine); } } catch (IOException io) { System.out.println("File IO exception" + io.getMessage()); } finally { // Need another catch for closing // the streams try { if (inputStream != null) { inputStream.close(); } } catch (IOException io) { System.out.println("Issue closing the Files" + io.getMessage()); } } } }
EmailAddresses.txt file contents:
In case the code block compiles terribly in this question:
20 21 2224278 23 25 26 29 30 31 32 33 34 35 36 37 38 39 40 1 12 13 14 15 16 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 0 */ public class SDEV425_1_Carnahan_Joshua { } /** * @param args the command line arguments */ public static void main(String[] args) { // Read the filename from the command line argument } String filename= args [0]; Buffered Reader inputStream null; String fileLine; try { inputStream = new Buffered Reader(new FileReader(fileName: filename)); System.out.println(x: "Email Addresses:"); // Read one Line using Buffered Reader } while ((fileLine = inputStream.readLine()) != null) { System.out.println(x: fileLine); } } catch (IOException io) { System.out.println("File 10 exception" + io.getMessage()); } finally { // Need another catch for closing // the streams try { if (inputStream != null) { inputStream.close(); }| } catch (IOException io) { System.out.println("Issue closing the Files" + io.getMessage()); }
Step by Step Solution
There are 3 Steps involved in it
It seems some syntax errors in the code Here is correct one import javaioBufferedReader import javai... View full answer
Get step-by-step solutions from verified subject matter experts
