Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions readwrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,43 @@
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) {
e.printStackTrace();
}
}

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;
}
}