Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package StreamsFilesAndDirectories4;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.*;
- public class WriteToFile {
- public static void main(String[] args) throws IOException {
- String pathIn = "input.txt";
- String pathOut = "output.txt";
- Set<Character> forbiddenSymbols = new HashSet<>();
- Collections.addAll(forbiddenSymbols, '.', ',', '!', '?');
- try (FileInputStream in = new FileInputStream(pathIn);
- FileOutputStream out = new FileOutputStream(pathOut)) {
- int oneByte = in.read();
- while (oneByte >= 0) {
- char myByteAsChar = (char) oneByte;
- if (!forbiddenSymbols.contains(myByteAsChar)) {
- out.write(oneByte);
- }
- oneByte = in.read();
- }
- } catch (IOException e){
- throw new RuntimeException(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment