私はシミュレータを実行しようとしていますが、主にいくつかの問題があります。 - コードはプログラムの最後に値を表示しません - コード実際にファイルを作成していません
- 私はかなり疲れていますので、私が作った愚かな間違いや私が残した細部を許してください。Javaコードがテキストファイルへの書き込みに失敗しました
私はウェブサイトを探索していると私は私が私が私のために動作するように最初のリンクからコードを編集することができると思ったが、それこの
What is the simplest way to write a text file in java
と
how to write to text file outside of netbeans
を見つけましたうまくいきませんでした(ここで見ているものはどれですか)
2番目のページはもっとシンプルに見えますが無い周囲のコードはそうイムない状況が何であるかを確認してくださいと私は
import java.util.Random;
import java.util.Scanner;
import java.io.*;
/*
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
*/
public class SimClass {
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in) ;
Random randomNumbers = new Random();
//create object from random class
//create self explanaroty input parameters
int pkt_in_q = 0 ;
int pkt_dropped = 0;
int input ;
int output ;
int buffer ;
int x ;
double y ;
//ask for values for buffer size. input rate, output rate
y = randomNumbers.nextDouble();
//attempt to assign a random number to the variable and
/*here you should get user input.
buffer size, # of repitions , if
*/
//fix this
System.out.print("Enter an integer for the input rate ");
input = keyboard.nextInt();
System.out.print("Enter an integer for the output rate ");
output = keyboard.nextInt();
System.out.print("What is the buffer size ");
buffer = keyboard.nextInt();
for (x = 1000000; x >=0 ; x--)
{ /*
simulate # of packets dropped/in the que,
create file, write results to file, output results,
*/
if (y > input/(output/buffer))
{
if (pkt_in_q < buffer)
{
pkt_in_q++ ;
}
else
{
pkt_dropped++ ;
}
//if statement should terminate here
}
else
if (pkt_in_q > 0)
{
pkt_in_q -- ;
}
}
/*
create file, write results to file, output results,
*/
try { /*this seeems to be the problem, the program is either not doing
anything with this or not making the results visible
*/
String content =(" pkt_in_q is " + pkt_in_q +
"pkt_dropped is " + pkt_dropped);
File file = new File("C:/Temp/inputFile.txt");
// if file doesnt exists, then create it
if (!file.exists())
{
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
try (BufferedWriter bw = new BufferedWriter(fw))
{
bw.write(content);
bw.close();
}
System.out.println("packets dropped value is = " +
pkt_dropped + "packets in q value is = " + pkt_in_q);
}
catch (IOException e)
{
//e.printStackTrace();
}
}
}
コードを_debugging_しようとしましたか?これは、Stack Overflow IMHOへの投稿よりも役に立ちます。 –
なぜあなたは例外を抑制していますか?彼らは間違っていることをあなたに示します。 – tak3shi
ティム私はnetbeansを使用していますが、コードはエラーを投げていません。また、 "実行"ボタンの横にある "デバッグ"オプションはグレー表示されていますが、suggegstingはエラーがなく、エラーは論理的または組織的です。 武生、あなたが何を指しているのかよくわかりません。詳しく教えてください。私は、コードについて約80%の理解があると言います。上記。私は他の場所からコードをcoppiedと言ったように。 – Anonymous