Skip to content

Instantly share code, notes, and snippets.

@rmg007
Created October 29, 2022 16:34
Show Gist options
  • Save rmg007/90e870b85ba9c441c3124e6e96ef7d85 to your computer and use it in GitHub Desktop.
Save rmg007/90e870b85ba9c441c3124e6e96ef7d85 to your computer and use it in GitHub Desktop.
CharArrayReader Writer Example
import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.FileWriter;
import java.io.IOException;
public class CharArrayReaderWriter {
static String filePath = "/Users/ryan/Desktop/file.txt";
public static void main(String[] args) throws IOException {
String word = "java";
char[] chars = word.toCharArray();
//try(CharArrayReader car = new CharArrayReader(chars)){
// int i;
// while ((i = car.read()) != -1){
// System.out.println((char) i);
// }
//}
try(CharArrayWriter caw = new CharArrayWriter();
FileWriter fw = new FileWriter(filePath)){
caw.write("hello Java");
caw.write("hello Java2");
System.out.println(caw);
caw.writeTo(fw);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment