Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.nio.ByteBuffer;
- public class Main {
- // InputSteram
- // OutputStream
- // FileInputStream организация побайтового считывания информации
- // OutputStream
- // FileOutputStream( " /*file*/ ", true/false); true-дозапись в конец
- // write(byte b);
- // (byte[] b);
- // (byte[] b, offset, count);
- //s.toCharArray()[i];
- // s.getBytes("UTF-8"); // указываем кодировку/строка; "UTF-8" по умолчанию
- // ("UTF-16");
- // ("windows-1251");
- // DataInputStream
- // Output
- // DataOutputStream( new FileInputStream( ));
- // write char( );
- // long( );
- // double( );
- // writeUTF(String s);Integer.toString().getBytes();string.getBytes();
- public static void main(String[] args) {
- String s = "abc_абв";
- try {
- for (int i = 0; i < s.length(); i++) {
- System.out.println(s.codePointAt(i)); //вернет позицию элемента i
- }
- } catch (Exception ex) {
- }
- for(int i = 0; i < 3; i++) {
- String utf = "UTF-8";
- if(i==1)
- utf = "UTF-16";
- else if(i==2)
- utf = "windows-1251";
- try (FileOutputStream b = new FileOutputStream(i+".txt")) {
- b.write(s.getBytes(utf));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- try (DataOutputStream d = new DataOutputStream(new FileOutputStream( "11.txt"))) {
- d.writeUTF(String.valueOf(s.getBytes()));
- d.writeInt(ByteBuffer.wrap(s.getBytes()).getInt());
- byte [] n = s.getBytes();
- for(int i = 0; i < s.getBytes().length; i++) {
- boolean bb = n[i]!=0;
- d.writeBoolean(bb);
- }
- d.writeDouble(ByteBuffer.wrap(s.getBytes()).getDouble());
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- ; //вся работа с файлами осуществляется в трай-кэтч
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement