01文件读写

文件读取


    Source source = null;

    BufferedSource bufferedSource = null;
    try {
        File file = new File("resources/test.txt");

        source = Okio.source(file);

        bufferedSource = Okio.buffer(source);

        String content = bufferedSource.readUtf8();

        System.out.println(content);

    } catch (FileNotFoundException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    } finally {

        closeQuietly(bufferedSource);

    }

文件写入

  Sink sink = null;
    BufferedSink bufferedSink = null;

    try {

        File dest = new File("resources/dest.txt");

        sink = Okio.sink(dest);

        bufferedSink = Okio.buffer(sink);

        bufferedSink.writeUtf8("11111111111");

    } catch (FileNotFoundException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    } finally {

        closeQuietly(bufferedSink);

    }

results matching ""

    No results matching ""