diff --git a/readwrite.java b/readwrite.java index a2a1c90..fc23c17 100644 --- a/readwrite.java +++ b/readwrite.java @@ -5,19 +5,21 @@ import java.io.PrintWriter; // Reads a file -public class readWrite { - public readWrite(String inputFile) throws IOException { +public class readwrite { + public String read(String inputFile) throws IOException { + String str = ""; File file = new File(inputFile); BufferedReader reader = new BufferedReader(new FileReader(file)); String line; while ((line = reader.readLine()) != null) { - System.out.println(line); + str += line; } reader.close(); + return str; } // Asks for a file and a text string, writes the string into the file - public void writeCode(String codeFile, String text) throws IOException { + public void write(String codeFile, String text) throws IOException { try (PrintWriter writer = new PrintWriter(codeFile)) { writer.println(text); } catch (IOException e) { @@ -25,21 +27,21 @@ public void writeCode(String codeFile, String text) throws IOException { } } - public static void main(String[] args) { + // public static void main(String[] args) { + // try { + // readwrite rw = new readwrite("input.txt"); + // rw.writeCode("output.txt", "aidan rahill is my baby boy i love him"); + // } catch (IOException e + + public int countCharacters(String fileName) throws IOException { + int count; try { - readWrite rw = new readWrite("input.txt"); - rw.writeCode("output.txt", "aidan rahill is my baby boy i love him"); + count = read(fileName).length(); } catch (IOException e) { + // TODO Auto-generated catch block e.printStackTrace(); + count = 0; } - }} - - - - - - - - - - + return count; + } +}