#java buffer and file reader help

30 messages · Page 1 of 1 (latest)

sly stag
#
public class upload
{
    public static void main(String[] args) throws IOException 
    {
        PrintWriter pw = new PrintWriter("output.txt");
     BufferedReader br = new BufferedReader(new FileReader("upp/400.txt"));     
     for (int i =0 ; i<3;i++)
     {
       br = new BufferedReader(new FileReader("upp/40"+Integer.toString(i)+".txt"));
       String line = br.readLine();
        while (line != null)
        {
            pw.println(line);
            line = br.readLine();
        }
     }
        pw.flush();
        br.close();
        pw.close();
    }
}```



i want to concat / merge 3 files 
400.txt
royal glacierBOT
#

This post has been reserved for your question.

Hey @sly stag! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

sly stag
#

i want 400.txt 401.txt 402.txt to be concat / merge

#

it works but change the content of the files

#
output
48ef bfbd 6412 5608 0a00 0000 5641 6405
0a73 6175 7261 6268 2073 6175 7261 6268
680a 7361 7261 7377 6174 2030 3830 390a
#
expected 
123 
uvfdis
[]\
woeful urchin
sly stag
#

i am on ubuntu

woeful urchin
#

windows

sly stag
#

it works on online compiler

royal glacierBOT
#
windows
sly stag
woeful urchin
#

make sure they are all in utf-8

sly stag
#

nothing changed

#
public class upload
{
    public static void main(String[] args) throws IOException 
    {
        PrintWriter pw = new PrintWriter("output.txt","UTF-8");
     BufferedReader br = new BufferedReader(new FileReader("upp/400.txt"));    
     for (int i =0 ; i<3;i++)
     {
       br = new BufferedReader(new FileReader("upp/40"+Integer.toString(i)+".txt"));
       String line = br.readLine();
        while (line != null)
        {
            pw.println(line);
            line = br.readLine();
        }
     }
        pw.flush();
        br.close();
        pw.close();
    }
}```
woeful urchin
#

400.txt, 401.txt, 402.txt

sly stag
#
0123
45612
456123
#

these are the data

frosty igloo
#
try (
  var in1 = Files.newInputStream("400.txt");
  var in2 = Files.newInputStream("401.txt");
  var in3 = Files.newInputStream("402.txt");
  var out = Files.newOutputStream("out.txt");
) {
  in1.transferTo(out);
  in2.transferTo(out);
  in3.transferTo(out);
}
#

this should realistically be all you need to concatenate file contents into one file

blazing vault
royal glacierBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

sly stag
#

The fact is .... Java is executing properly

#

The metadata of the files is creating problems

#

UTF-8 ......and all that stuff

blazing vault
#

You should try and be more vague