# Problem in creating root file

**URL:** <https://root-forum.cern.ch/t/problem-in-creating-root-file/49390>\
**Category:** Newbie\
**Created:** [March 29, 2022, 3:32am UTC](https://root-forum.cern.ch/t/problem-in-creating-root-file/49390 "2022-03-29T03:32:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [March 29, 2022, 3:32am UTC](https://root-forum.cern.ch/t/problem-in-creating-root-file/49390/1 "2022-03-29T03:32:54Z")

</div>

I had been having problem in creating root file;  
I have been using given code to create tree and root file,  
[current\_ntuple.C](https://root-forum.cern.ch/uploads/short-url/dkCPvvaATFJs7iIEoNsm1YnJDUS.C) (656 Bytes)

Thank You.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [March 29, 2022, 6:17am UTC](https://root-forum.cern.ch/t/problem-in-creating-root-file/49390/2 "2022-03-29T06:17:00Z")

</div>

And what is the problem?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 29, 2022, 6:44am UTC](https://root-forum.cern.ch/t/problem-in-creating-root-file/49390/3 "2022-03-29T06:44:56Z")

</div>

You macro is:

```auto
void current_ntuple()
{
   TFile *f = new TFile("filt.root","RECREATE"); // create the root file
   TTree *T = new TTree("curr","data from txt file"); //create the tree for current
   Long64_t nlines = T->ReadFile("JanToMar_11am.txt","Current");//read the file, creating names for the branches
   printf(" found %lld points\n", nlines);
   T -> Write(); //write data onto root file
   f -> Close();
}

```

To run it we are missing the file `JanToMar_11am.txt `.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 29, 2022, 7:21am UTC](https://root-forum.cern.ch/t/problem-in-creating-root-file/49390/4 "2022-03-29T07:21:53Z")

</div>

BTW. Instead of “`f->Close();`”, use: `delete f; // automatically deletes T, too`
