Created
October 29, 2022 16:34
-
-
Save rmg007/90e870b85ba9c441c3124e6e96ef7d85 to your computer and use it in GitHub Desktop.
CharArrayReader Writer Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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