-4

I have a complicated project with multiple 50+ files.

I would like to extract all these files into one single one, labeled with were they came from.

I might have code setup like this:

src
|
+ - Engine (folder)
|   |
|   + - Engine.java
|   + - RenderExample.java
|
+ - test.java
+ - runningOutOfFileNames.java

I want all of that code extract to a single file to look like this:

src/Engine/Engine.java:
{...Code...}

src/Engine/RenderExample.java
{...Code...}

src/test.java
{...Code...}

src/runningOutOfFileNames.java
{...Code...}

I realise that this file will not be compilable, but I need to hand in the code for a school project (that was not intended to include code) and we are only allowed to submit one doc :/

  • The formatting of the file does not have to be exactly like this, it was just an example :) – user3718254 Jan 12 '15 at 20:13
  • 1
    Do you have a question? All you've done is describe a program. Please show what you've tried and what the specific issue is with your code. – tnw Jan 12 '15 at 20:19

4 Answers4

1

A few things to look into:

  1. Look into finding and getting all files in a directory [Example]
  2. Look into reading in files (LOTS of examples out there)
  3. Similarly, look into writing out files

Oracle has a Reading, Writing, Creating Files Tutorial that can you help you a lot

Community
  • 1
  • 1
Ascalonian
  • 14,409
  • 18
  • 71
  • 103
0

If you are using a Unix like operating system, try running the following in a terminal at the project directory.

find . -name '*.java' -exec echo '{}' \; -exec cat '{}' \;
ehecatl
  • 170
  • 1
  • 8
0
  1. BE VERY CAREFUL! I'm saying this because I have wiped out my source files on more than one occasion trying to do this sort of thing

  2. State your src directory in your code somewhere, either statically or at runtime.

  3. Recursively descend into folder & sub-folders (see File.listFiles(...) there are a couple of filters you can use), looking for source (.java) files, maintaining your stack
  4. When you find a source file, write the stack path followed by a copy of the file into your single file.
  5. If you want to get fancy, and you have everything else working, you could hook this up to DropWindow, so you can just drag and drop the next time you need to do this
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
0

Unix rules!

find . -name "*.java" | xargs -I file sh -c "echo file; cat file"
Rudi Angela
  • 1,463
  • 1
  • 12
  • 20