Change where reads file
This commit is contained in:
parent
b00c0b4300
commit
6642aa86f5
@ -1,6 +1,10 @@
|
|||||||
package edu.jt_kb.cs4308.compiler;
|
package edu.jt_kb.cs4308.compiler;
|
||||||
|
|
||||||
|
import edu.jt_kb.cs4308.compiler.FileManagement.FileReader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Driver {
|
public class Driver {
|
||||||
@ -13,26 +17,12 @@ public class Driver {
|
|||||||
public void start() {
|
public void start() {
|
||||||
File java = new File("src/edu/jt_kb/cs4308/compiler/resources/Java.txt");
|
File java = new File("src/edu/jt_kb/cs4308/compiler/resources/Java.txt");
|
||||||
File python = new File("src/edu/jt_kb/cs4308/compiler/resources/Python.txt");
|
File python = new File("src/edu/jt_kb/cs4308/compiler/resources/Python.txt");
|
||||||
readFile(java);
|
List<String> code = new ArrayList<>();
|
||||||
System.out.println();
|
code = FileReader.readFile(java);
|
||||||
readFile(python);
|
System.out.println(code);
|
||||||
|
code = FileReader.readFile(python);
|
||||||
|
System.out.println(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void readFile(File file) {
|
|
||||||
try (Scanner input = new Scanner(file)) {
|
|
||||||
while (input.hasNextLine()) {
|
|
||||||
String line = input.nextLine();
|
|
||||||
char[] chars = line.toCharArray();
|
|
||||||
String result = "[";
|
|
||||||
for (char curr : chars) {
|
|
||||||
result += curr;
|
|
||||||
}
|
|
||||||
result += "]";
|
|
||||||
System.out.println(result);
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,21 @@
|
|||||||
package edu.jt_kb.cs4308.compiler.FileManagement;
|
package edu.jt_kb.cs4308.compiler.FileManagement;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class FileReader {
|
public class FileReader {
|
||||||
|
public static List<String> readFile(File file) {
|
||||||
|
List<String> codeLines = new ArrayList<>();
|
||||||
|
try (Scanner input = new Scanner(file)) {
|
||||||
|
while (input.hasNextLine()) {
|
||||||
|
String line = input.nextLine();
|
||||||
|
codeLines.add(line + " $");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return codeLines;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user