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
24 changes: 20 additions & 4 deletions Milo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@
import java.io.*;

public class Milo {
public void writeToFile(String s) throws IOException {
String fileName = "milo.txt";
public static void writeToFile(String s, String fileName) throws IOException {
// String fileName = "milo.txt";
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
pw.print(s);
pw.close();
}

public String readFromFile() throws IOException {
String fileName = "milobear.txt";
public static String readFromFile(String fileName) throws IOException {
// String fileName = "milobear.txt";
BufferedReader br = new BufferedReader(new FileReader(fileName));
String s = br.readLine();
br.close();
return s;
}
public static int countCharacters (String fileName) throws IOException
{
int count = 0;
BufferedReader br = new BufferedReader(new FileReader(fileName));
while (br.ready())
{
br.read();
count++;
}
return count;
}
public static void main(String[] args) throws IOException {
// writeToFile("milo","milo.txt");
System.out.println(readFromFile ("milo.txt"));
System.out.println(countCharacters("milo.txt"));
}
}