Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import java.io.BufferedOutputStream;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.nio.charset.StandardCharsets;
  6. import java.nio.file.Files;
  7. import java.nio.file.Path;
  8. import java.nio.file.Paths;
  9. import java.util.Iterator;
  10. import java.util.stream.Stream;
  11.  
  12.  
  13. public class StringToBytes {
  14.  
  15.  
  16. private static void convertor(Stream<String> input) throws IOException
  17. {
  18.  
  19. File file = new File("byteTest.txt");
  20. BufferedOutputStream writer = new BufferedOutputStream(new FileOutputStream(file));
  21.  
  22. Iterator<String> it= input.iterator();
  23.  
  24. while (it.hasNext())
  25. {
  26. byte []b= it.next().getBytes();
  27. writer.write(b);
  28.  
  29. }
  30. writer.close();
  31. }
  32.  
  33. public static void main(String args[]) throws IOException{
  34. Path path= Paths.get("test.txt");
  35.  
  36. Stream<String>lines=Files.lines(path, StandardCharsets.UTF_8);
  37. convertor(lines);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement