Advertisement
lashrone1

in_ou

Nov 27th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. import java.io.*;
  2. import java.nio.ByteBuffer;
  3.  
  4. public class Main {
  5.  
  6.  
  7. // InputSteram
  8. // OutputStream
  9.  
  10. // FileInputStream организация побайтового считывания информации
  11. // OutputStream
  12. // FileOutputStream( " /*file*/ ", true/false); true-дозапись в конец
  13. // write(byte b);
  14. // (byte[] b);
  15. // (byte[] b, offset, count);
  16.  
  17. //s.toCharArray()[i];
  18.  
  19. // s.getBytes("UTF-8"); // указываем кодировку/строка; "UTF-8" по умолчанию
  20. // ("UTF-16");
  21. // ("windows-1251");
  22.  
  23. // DataInputStream
  24. // Output
  25. // DataOutputStream( new FileInputStream( ));
  26. // write char( );
  27. // long( );
  28. // double( );
  29. // writeUTF(String s);Integer.toString().getBytes();string.getBytes();
  30.  
  31.  
  32. public static void main(String[] args) {
  33. String s = "abc_абв";
  34.  
  35. try {
  36. for (int i = 0; i < s.length(); i++) {
  37. System.out.println(s.codePointAt(i)); //вернет позицию элемента i
  38. }
  39. } catch (Exception ex) {
  40. }
  41.  
  42. for(int i = 0; i < 3; i++) {
  43. String utf = "UTF-8";
  44. if(i==1)
  45. utf = "UTF-16";
  46. else if(i==2)
  47. utf = "windows-1251";
  48.  
  49. try (FileOutputStream b = new FileOutputStream(i+".txt")) {
  50. b.write(s.getBytes(utf));
  51. } catch (FileNotFoundException e) {
  52. e.printStackTrace();
  53. } catch (IOException e) {
  54. e.printStackTrace();
  55. }
  56. }
  57.  
  58. try (DataOutputStream d = new DataOutputStream(new FileOutputStream( "11.txt"))) {
  59.  
  60. d.writeUTF(String.valueOf(s.getBytes()));
  61.  
  62. d.writeInt(ByteBuffer.wrap(s.getBytes()).getInt());
  63.  
  64. byte [] n = s.getBytes();
  65. for(int i = 0; i < s.getBytes().length; i++) {
  66. boolean bb = n[i]!=0;
  67. d.writeBoolean(bb);
  68. }
  69.  
  70. d.writeDouble(ByteBuffer.wrap(s.getBytes()).getDouble());
  71.  
  72. } catch (FileNotFoundException e) {
  73. e.printStackTrace();
  74. } catch (IOException e) {
  75. e.printStackTrace();
  76. }
  77.  
  78.  
  79.  
  80. ; //вся работа с файлами осуществляется в трай-кэтч
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement