Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.io.Console;
  2. import java.util.ArrayList;
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6.  
  7. public static void main( String[] args ) {
  8.  
  9.     Console console = System.console();
  10.  
  11.     // Read in database name and columns
  12.     String strDBName = console.readLine( "<Enter the database name (this will become the filename)\n> " );
  13.  
  14.     // Try to create this file
  15.     File file = new File( strDBName + ".txt" );
  16.     try {
  17.         if (file.createNewFile())
  18.             System.out.println("Successfully created file");
  19.         else
  20.             // Report error and quit if we couldn't create this file
  21.         return System.out.println("Error, file already exists.");
  22.     } catch (IOException ioe) {
  23.         return;
  24.     } // end catching exception
  25.  
  26.     // Add our attribute names/
  27.     ArrayList<String> strAttributes= new ArrayList<String>();
  28.     while( true ) {
  29.         // Read in a new attribute name
  30.         String strAttribute= console.readLine( "<Enter a new attribute name (or 'q' when you're finished)\n> " );
  31.  
  32.         // Break if we hit any of these strings
  33.         if( strAttribute == "" || strAttribute == "q" || strAttribute == "Q" || strAttribute == "quit" ) break;
  34.  
  35.         // Append the attribute to our list
  36.         strAttributes.add( strAttribute );
  37.  
  38.     } // end while reading column names
  39.  
  40.     // Output our text file
  41.     PrintStream out= new PrintStream( new FileOutputStream(file) );
  42.     for( int iAttribute= 0; iAttribute<; iAttribute++ ) {
  43.  
  44.         out.print( strAttributes[iAttribute] );
  45.  
  46.         // Add entries
  47.         for( int iEntry= 0; iEntry<100; iEntry++ )
  48.             out.print( "|" + (iEntry*113)%100 );
  49.  
  50.         // Add a newline before we go to the next attribute
  51.         out.println();
  52.  
  53.     } // end for attributes
  54.  
  55. } // end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement