Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    importo variabili da file in java

    ciao ragazzi, ai primi passi in Java volevo sapere se qualcuno fosse in grado di spiegarmi semplicemente come importare valori numerici da un file di testo in una classe java. Grazie in anticipo.
    Walk fast, chew slowly.
    "We used students as subjects because rats are expensive and you get too attached to them"

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    271
    Non č che hai sbagliato forum????

    Qui si parla di VB e VB.Net

  3. #3
    nooo adesso ho ripostato...che casoiiiiino oggi...scusa IKON, boh cancellami uno dei due post...
    Walk fast, chew slowly.
    "We used students as subjects because rats are expensive and you get too attached to them"

  4. #4
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    Properties properties = new Properties();
    FileInputStream FIS = new FileInputStream("file.properties");
    properties.load(FIS);
    FIS.close();

    int variable = Integer.parseInt(properties.getProperty("variable" ));

    il file deve essere in questo formato

    variable=2

  5. #5
    ok, grazie mille, ora esiste un modo per far ignorare all´applicazione java parte della linea del documento di testo?
    Walk fast, chew slowly.
    "We used students as subjects because rats are expensive and you get too attached to them"

  6. #6
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    la classe Porperties si aspetta un formato come ho scritto

    se hai esigenze strane usa altri metodi

  7. #7
    ok, allora, date un occhiata a cosa sono andato a combinare. Il tutto funziona piuttosto bene, quello che fa e´prendere degli int da un file di testo e metterli in un array. Ora, mi piacerebbe che il file di testo abbia un formato del tipo
    Numero utenti: 35
    che si prenda il 35 e ignori tutto il resto, se nel file id testo uso:
    35 : numero di utenti funziona correttamente, e´piu´che altro una questione di stile, qualche aiuto?

    int[] a1 = new int[10];
    for(int i=0; i<a1.length; i++) {a1[i] = 0;}

    int i = 0;
    String s = null;
    StringTokenizer st = null;
    BufferedReader in = new BufferedReader(new FileReader("Parameter1.txt"));
    while( (s=in.readLine()) != null)
    {
    st = new StringTokenizer(s);
    a1[i] = Integer.parseInt(st.nextToken());
    i++;
    }
    Walk fast, chew slowly.
    "We used students as subjects because rats are expensive and you get too attached to them"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.