Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.Console;
- import java.util.ArrayList;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public static void main( String[] args ) {
- Console console = System.console();
- // Read in database name and columns
- String strDBName = console.readLine( "<Enter the database name (this will become the filename)\n> " );
- // Try to create this file
- File file = new File( strDBName + ".txt" );
- try {
- if (file.createNewFile())
- System.out.println("Successfully created file");
- else
- // Report error and quit if we couldn't create this file
- return System.out.println("Error, file already exists.");
- } catch (IOException ioe) {
- return;
- } // end catching exception
- // Add our attribute names/
- ArrayList<String> strAttributes= new ArrayList<String>();
- while( true ) {
- // Read in a new attribute name
- String strAttribute= console.readLine( "<Enter a new attribute name (or 'q' when you're finished)\n> " );
- // Break if we hit any of these strings
- if( strAttribute == "" || strAttribute == "q" || strAttribute == "Q" || strAttribute == "quit" ) break;
- // Append the attribute to our list
- strAttributes.add( strAttribute );
- } // end while reading column names
- // Output our text file
- PrintStream out= new PrintStream( new FileOutputStream(file) );
- for( int iAttribute= 0; iAttribute<; iAttribute++ ) {
- out.print( strAttributes[iAttribute] );
- // Add entries
- for( int iEntry= 0; iEntry<100; iEntry++ )
- out.print( "|" + (iEntry*113)%100 );
- // Add a newline before we go to the next attribute
- out.println();
- } // end for attributes
- } // end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement