problem with a program...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Marco_Salghetti
Posted On:   Wednesday, May 22, 2002 07:43 AM

I've a program that run well, but I'd like to add an operation.... When the operation is terminated there is a menu that make 2 ask: 1- restart 2-end I want to add the voice: "restart with the same file", without reenter the path of the file, but I don't know how to do it. import java.io.*; import java.util.*; public class OperazioneFileMarco { public static void main (String[] args) { try { InputStreamReader reader = new InputStreamReader (System.in); BufferedReader console = new BufferedReader (reader); String entrata; int cPari = 1; int cDispari = 3; System.out.print ("Inserisci il fullpath del file da criptare: ")   More>>

I've a program that run well, but I'd like to add an operation....
When the operation is terminated there is a menu that make 2 ask: 1- restart 2-end
I want to add the voice: "restart with the same file", without reenter the path of the file, but I don't know how to do it.


			
import java.io.*;
import java.util.*;
public class OperazioneFileMarco {
public static void main (String[] args) {
try {
InputStreamReader reader = new InputStreamReader (System.in);
BufferedReader console = new BufferedReader (reader);
String entrata;
int cPari = 1;
int cDispari = 3;
System.out.print ("Inserisci il fullpath del file da criptare: ");
entrata = console.readLine();
String sorg = entrata;
FileInputStream sor = new FileInputStream(entrata);
BufferedInputStream file = new BufferedInputStream(sor);
String ris = sorg.substring(0, sorg.lastIndexOf("."))+"_criptato"+sorg.substring(sorg.lastIndexOf("."), sorg.length());
String ris1 = sorg.substring((sorg.lastIndexOf("\")+1), sorg.length());
FileOutputStream flout = new FileOutputStream(ris);
BufferedOutputStream fl = new BufferedOutputStream(flout);
boolean ciclo = false;
while (!ciclo) {
System.out.println ("
Scegliere l'operazione da fare:

1- Criptare

2- Decriptare

3- Leggere
");
entrata = console.readLine();
int i = Integer.parseInt(entrata);
System.out.print ("
");
boolean eof = false;
int count = 0;
switch (i) {
case 1 : System.out.print("
");
while (!eof) {
int input = file.read();
if (input == -1)
eof = true;
else {
if ((input % 2) == 0)
input = input + cPari;
else
input = input + cDispari;
count++;
System.out.println ("Sto elaborando l'informazione richiesta");
fl.write(input);
}
}
System.out.println ("
Il fullpath del file criptato e': "+ris+"
");
break;
case 2 : System.out.print("
");
while (!eof) {
int input = file.read();
if (input == -1)
eof = true;
else {
if ((input % 2) == 0)
input = input - cDispari;
else
input = input - cPari;
count++;
System.out.println ("Sto elaborando l'informazione richiesta");
fl.write(input);
}
}
System.out.println ("
Il fullpath del file criptato e': "+ris+"
");
break;
case 3 : int caratteri = 0;
int car = 0;
System.out.print("
");
FileReader file1 = new FileReader (sorg);
BufferedReader buff = new BufferedReader (file1);
eof = false;
System.out.println ("Lettura del file "+ris1+":
");
while (!eof) {
String line = buff.readLine();
if (line == null)
eof = true;
else {
count++;
System.out.println (" "+line);
caratteri = line.length() + caratteri;
for (int c=0; i < line.length(); i++) {
if (line.charAt(i) !=' ')
car++;
}
}
}
}
fl.flush();
System.out.println ("
Ora scegli:

1- Nuova operazione

2- Esci
");
entrata = console.readLine();
int a = Integer.parseInt(entrata);
System.out.print ("
");
switch (a) {
case 1 : ciclo = false;
System.out.print ("Inserisci il fullpath del file da criptare: ");
entrata = console.readLine();
sorg = entrata;
sor = new FileInputStream(entrata);
file = new BufferedInputStream(sor);
ris = sorg.substring(0, sorg.lastIndexOf("."))+"_criptato"+sorg.substring(sorg.lastIndexOf("."), sorg.length());
flout = new FileOutputStream(ris);
fl = new BufferedOutputStream(flout);
break;
case 2 : System.out.println("Arrivederci!!!
");
ciclo = true;
}
}
file.close();

fl.close();
}
catch (IOException ioe) {
System.out.println("ERRORE: " + ioe.toString());
}
}
}

   <<Less

Re: problem with a program...

Posted By:   AlessandroA_Garbagnati  
Posted On:   Wednesday, May 22, 2002 07:47 AM

Ciao Marco,

Can you just store somewhere the "last file used" (as a File object, maybe) and when you use your option you just reuse the content of that variable?
About | Sitemap | Contact