16
16
17
17
package main .java .jterm ;
18
18
19
+ import java .io .BufferedReader ;
19
20
import java .io .File ;
20
21
import java .io .FileWriter ;
21
22
import java .io .FileReader ;
@@ -141,43 +142,57 @@ public static void Delete(ArrayList<String> options)
141
142
142
143
/*
143
144
* ReadFile() void
145
+ * Changelog (#68)
144
146
*
145
- * Reads the specified files
147
+ * Reads the specified files and outputs the contents
148
+ * to the console.
146
149
*
147
150
* ArrayList<String> options - command options
148
151
*
149
152
* -h
150
153
* Prints help information
154
+ *
155
+ * Credit to @d4nntheman
151
156
*/
152
- public static void ReadFile (ArrayList <String > options )
153
- {
154
- String filename = "" ;
155
- for (String option : options )
156
- {
157
- if (option .equals ("-h" ))
158
- {
159
- System .out .println ("Command syntax:\n \t read [-h] [FILE]..." );
160
- return ;
161
- }
162
-
157
+ public static void ReadFile (ArrayList <String > options )
158
+ {
159
+
160
+ String filename = "" ;
161
+ for (String option : options )
162
+ {
163
+ if (option .equals ("-h" ))
164
+ {
165
+ System .out .println ("Command syntax:\n \t read [-h] [file1 file2 ...]\n \n Reads and outputs the contents of the specified files." );
166
+ return ;
167
+
168
+ }
169
+
163
170
filename = JTerm .currentDirectory + option ;
164
- File file = new File (filename );
165
- if (!file .exists ())
166
- {
171
+ File file = new File (filename );
172
+ if (!file .exists ())
173
+ {
167
174
System .out .println ("ERROR: File/directory \" " + option + "\" does not exist." );
168
- break ;
169
- }
170
-
171
- try (BufferedReader reader = new BufferedReader (new FileReader (file .getAbsolutePath ())))
172
- {
173
- String line = null ;
174
- while ((line = reader .readLine ()) != null )
175
- System .out .println (line );
176
- } catch (IOException e ) {
177
- e .printStackTrace ();
178
- return ;
179
- }
180
- }
181
- }
175
+ break ;
176
+
177
+ }
178
+
179
+ try ( BufferedReader reader = new BufferedReader (new FileReader (file .getAbsolutePath ())) )
180
+ {
181
+ System .out .println ("\n [JTerm - Contents of " + option + "]\n " );
182
+ String line = null ;
183
+ while ( (line = reader .readLine ()) != null )
184
+ System .out .println (line );
185
+
186
+ }
187
+ catch (IOException e )
188
+ {
189
+ e .printStackTrace ();
190
+ return ;
191
+
192
+ }
193
+
194
+ }
195
+
196
+ }
182
197
183
198
}
0 commit comments