Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void read() {
- String path = "/Users/pavel/Desktop/test/target_text.txt";
- try (BufferedInputStream in = new BufferedInputStream(
- new FileInputStream(path))) {
- byte[] bytes = new byte[1024];
- int amountData = in.read(bytes, 0, 1024);
- while (amountData != -1 && amountData == 1024) {
- sb.append(new String(bytes, "UTF8"));
- amountData = in.read(bytes, 0, 1024);
- }
- if (amountData != -1) {
- byte[] residue = new byte[amountData];
- System.arraycopy(bytes, 0, residue, 0, residue.length);
- sb.append(new String(residue, "UTF8"));
- }
- System.out.println(sb);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- int amountData = in.available()%1024;
- for(int n=0; n<amountData; n++){
- in.read(bytes, 0, 1024);
- }
- in.read(bytes, 0, in.available());
- String path = "/Users/pavel/Desktop/test/target_text.txt";
- StringBuilder sb = new StringBuilder();
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), Charset.forName("UTF-8")))) {
- String line;
- while ((line = reader.readLine()) != null) {
- sb.append(line + "n");
- }
- System.out.println(sb);
- } catch (IOException e) {
- e.printStackTrace();
- }
Add Comment
Please, Sign In to add comment