Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

help! empty output file


ghost's Avatar
0 0

Hello, I have source code that builds correctly, however, after the program terminates the output file produced is empty.

Here is my source code:

import java.io.*; import java.util.Scanner; public class project { public static void main( String args[] ) { try { FileInputStream fis = new FileInputStream("Foobar.java"); DataInputStream dis = new DataInputStream(fis); BufferedReader br = new BufferedReader(new InputStreamReader(dis));

String line = ""; String se = ""; String var=""; String t=""; Scanner in = new Scanner( System.in ); int input;

// Create a new file output stream // connected to "myfile.txt" PrintWriter pw = new PrintWriter ( new BufferedWriter( new FileWriter("Foobar.java")));

// declare a file output object // declare a print stre p = new PrintStream( out );

// Connect print stream to the output stream

System.out.println( "Choose the correct option to create appropriate method(s) for each variable found\\n"); System.out.println("Menu"); System.out.println( "(1) Set"); System.out.println( "(2) Get"); System.out.println( "(3) Both"); System.out.println( "(4) Skip");

input = in.nextInt(); // Here BufferedInputStream is added for fast reading. // dis.available() returns 0 if the file does not have more lines. while ((line = br.readLine()) != null) {

// this statement reads the line from the file and print it to // the console. line = br.readLine(); line.trim(); pw.write( line ); if( line.indexOf("private") != -1 ) { String [] newLine = line.split(" ");

t = newLine[7];

var = newLine[8]; t = t.replace( ';', ' ' ); var = var.replace( ';', ' ' ); switch( input ) {

case 1:

se+=prepareSet(t, var ); se+="\n";

break;

case 2: se+=prepareGet(t, var ); se+="\n";

break;

case 3: se+=prepareSet(t, var ); se+=prepareGet(t, var ); se+="\n";

break; case 4:

break; default: break;

} }

}//end of while if( input == 1 ) System.out.println("Set Methods Prepared…….Thank you!"); if( input == 2 ) System.out.println("Get Methods Prepared…….Thank you!"); if( input == 3 ) System.out.println("Both Set and Get Methods Prepared…….Thank you!"); if( input == 4 ) System.out.println("Nothing was Changed……Thank you!"); pw.println(se);

fis.close(); br.close(); dis.close(); pw.close(); // dispose all the resources after using them. }//END OF TRY

catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static String prepareSet( String ti, String v ) { String s = "public "+ ti+" set"+v + "(" + ti + " " + v + ")\n" + "{\n\tthis." +v+ "=" +v+";\n}\n";

return s;

} public static String prepareGet(String ti, String v ) { String s = "Public void get"+v + "()\n" + "{\nreturn this." +v + ";\n}\n"; return s; } }

HERE IS THE ASSIGNMENT (KIND OF LONG)

Due Date: 12/05/07 5:00PM (-10% per day late)

Objective:

Create a program to insert public accesors (setXX and getXX methods) into a java class.

Your program will accept a .java source file as a command line argument, and the output should be inserted into the file. The output should be written to the same file and file name as the input file.

Sample Input: (Foobar.java)

public class Foobar

{

private int _counter;

private String _firstName;

private Date birthDate;

public static void main(String[] args)

{

System.out.println("Hello World!" + FirstName);

}

}


ghost's Avatar
0 0

Did it ever occur to you to actually just post the CRITICAL PORTION? Fucking hell, your post is longer than most of the ARTICLES. If you actually expect any real answer, you need to edit your damn post.


ynori7's Avatar
Future Emperor of Earth
0 0

how come no one ever disables smileys in their code?


ghost's Avatar
0 0

please tell me…i'm begging you how do you disable those smileys.


ghost's Avatar
0 0

omg how stupid can you be?


Mb0742's Avatar
Ultimate Headshot
0 0

Solve your problems like a man. Guns are cheap now….


ghost's Avatar
0 0

NONE OF U ASS HOLES ARE HELPING…wat a bunch of snotty muthafuckas u all are ..and u call urself hackers down for the sharing of information..yet i receive more hate then help.:ninja:


ghost's Avatar
0 0

STFU & GTFO of our fora you piece of shit.


ghost's Avatar
0 0

Well u'll soon discover there are a**holes on this site. You just have to ignore them, and not to rush quickly but Zephyr u seem to be one of the most critical, 3/4th the posts of seen by u , are like screw you or you gay, stupid, etc. how dumb, idiots, , if u get my point. I'd help you Wet, but im not good in this topic, so kind of a useless post here, but just lettin ya know how it is, peace. and gl with ur programming


Uber0n's Avatar
Member
0 0

I can see the error in the code. It's Java, not C++ :D

jk


spyware's Avatar
Banned
0 0

S1L3NTKn1GhT wrote: Well u'll soon discover there are a**holes on this site. You just have to ignore them, and not to rush quickly but Zephyr u seem to be one of the most critical, 3/4th the posts of seen by u , are like screw you or you gay, stupid, etc. how dumb, idiots, , if u get my point. I'd help you Wet, but im not good in this topic, so kind of a useless post here, but just lettin ya know how it is, peace. and gl with ur programming

Shut the fuck up you moron. You are worthless. And the topicstarter, start EDITING YOUR POST (HINT HINT HINT).