Skip to content

Commit 32b9976

Browse files
committedJul 10, 2017
Update ReadFile
View changelog entry #68 for details.
1 parent 6800512 commit 32b9976

File tree

4 files changed

+52
-29
lines changed

4 files changed

+52
-29
lines changed
 

‎changelog.txt

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
(#68)[7/10/2017-18:03 0.4.0 Sergix]
2+
Merged PR #17 which included the ReadFile() function in Files.java written by @d4nntheman.
3+
- Closes issue #16
4+
Slight changes to Files.ReadFile() code spacing.
5+
Added BufferedReader to imports of Files.java (fixes Travis CI build fail).
6+
Pushed updates to Git.
7+
18
(#67)[7/6/2017-11:25 0.4.0 Sergix]
29
Fixed issue #15 (2). (https://github.com/Sergix/JTerm/issues/15)
310
ChangeDir() accepts directory paths enclosed in quotes.

‎src/main/java/jterm/Files.java

+44-29
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package main.java.jterm;
1818

19+
import java.io.BufferedReader;
1920
import java.io.File;
2021
import java.io.FileWriter;
2122
import java.io.FileReader;
@@ -141,43 +142,57 @@ public static void Delete(ArrayList<String> options)
141142

142143
/*
143144
* ReadFile() void
145+
* Changelog (#68)
144146
*
145-
* Reads the specified files
147+
* Reads the specified files and outputs the contents
148+
* to the console.
146149
*
147150
* ArrayList<String> options - command options
148151
*
149152
* -h
150153
* Prints help information
154+
*
155+
* Credit to @d4nntheman
151156
*/
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\nReads and outputs the contents of the specified files.");
166+
return;
167+
168+
}
169+
163170
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+
{
167174
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+
}
182197

183198
}

‎src/main/java/jterm/JTerm.java

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public static boolean Parse(ArrayList<String> options)
200200
break;
201201

202202
case "read":
203+
Files.ReadFile(options);
203204
break;
204205

205206
/*case "connect":
1.05 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.