[ voxi @ 02.01.2006. 11:17 ] @
Moze li mi neko dati najjednostavniji primer upisa u txt datoteku i citanje iz nje ajd molim VAS treba mi to za zadatak. HVALA. [Ovu poruku je menjao veljaradenkovic dana 03.01.2006. u 00:48 GMT+1] |
[ voxi @ 02.01.2006. 11:17 ] @
[ nemnesic @ 02.01.2006. 17:59 ] @
Code: import java.io.*; public class MyFirstFileWritingApp { // Main method public static void main (String args[]) { // Stream to write file FileOutputStream fout; try { // Open an output stream fout = new FileOutputStream ("myfile.txt"); // Print a line of text new PrintStream(fout).println ("hello world!"); // Close our output stream fout.close(); } // Catches any error conditions catch (IOException e) { System.err.println ("Unable to write to file"); System.exit(-1); } } } i Code: import java.io.*; public class MyFirstFileReadingApp { // Main method public static void main (String args[]) { // Stream to read file FileInputStream fin; try { // Open an input stream fin = new FileInputStream ("myfile.txt"); // Read a line of text System.out.println( new DataInputStream(fin).readLine() ); // Close our input stream fin.close(); } // Catches any error conditions catch (IOException e) { System.err.println ("Unable to read from file"); System.exit(-1); } } } let me know if it works -- Every Problem Has A Solution [ voxi @ 07.01.2006. 14:17 ] @
Hvala za ovo do sada. (Sa malim akasnjenjem) Ovo mi je dosta koristilo ali sada mi treba da ja odredjeni podatak u datoteci promenim kako to da uradim ajd dajte mi neki primer molim vas.
HVALA, I SRETNI VAM SVI JANUARSKI PRAZNICI. [Ovu poruku je menjao veljaradenkovic dana 07.01.2006. u 16:31 GMT+1] [ nemnesic @ 07.01.2006. 16:35 ] @
Hristos Se Rodi!
A jel znas kako bi ja to uradio? Ne... e ovako... jabi read ceo text u array (matrice, niz...ne znam kako ih zovete tamo ;)) onda bi trazio ono sto hocu da zamenim...i posle toga bi to samenio...i onda bi ponovo Write text u taj isti text file... primer nemogu sada da pisem...ali je na istom principu...read & write I/O files cujemo se nn -- Every Problem Has A Solution [ voxi @ 08.01.2006. 18:04 ] @
Nema problema ne ce se ponoviti veljaradenkovic!
De mi recite kako da ocitam sistemsko vreme i datum, ako moze kod po mogucnosti. Nemnesic sto se tice tvoj ideje ona je OK ali ima li drugi nacin Hvala. -- Internal Virus Database is out-of-date. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 267.13.10 - Release Date: 29.11.2005 [ nemnesic @ 09.01.2006. 19:25 ] @
citanje vremena i datuma:
Code: import java.text.*; import java.util.*; public class my_data { private SimpleDateFormat formatter; private Date currentdate; public my_data() { currentdate=new Date(); formatter=new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault()); } public int getDay() { formatter.applyPattern("d"); return Integer.parseInt(formatter.format(currentdate)); } public int getMonth() { formatter.applyPattern("M"); return Integer.parseInt(formatter.format(currentdate)); } public int getYear() { formatter.applyPattern("y"); return Integer.parseInt(formatter.format(currentdate)); } public int getHour() { formatter.applyPattern("h"); return Integer.parseInt(formatter.format(currentdate)); } public int getMinute() { formatter.applyPattern("m"); return Integer.parseInt(formatter.format(currentdate)); } } a zasto drugi nacin da menjas content file-a? mozda postoji ali daj mi prvo taj text file koji hoces da menjas, i kazi mi sta hoces da menjas... nn -- Every Problem Has A Solution [ voxi @ 09.01.2006. 21:11 ] @
Hvala kolega za ovo citanje vremena!
A sto se tice proemene u datoteci necu da te gnajvim nije to los metod ali razmisljao sam o tome da se to resi na soto manji racun operativne memorije nije nista ekstra I ako uratim tako profa ce prihvatiti U svako slucaju havala! -- No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 267.14.15 - Release Date: 6.1.2006 [ nemnesic @ 10.01.2006. 06:40 ] @
e pogledaj ovo
Code: static String replace( String str, String replace, String with ) { StringBuffer sb = null; String temp = str; boolean found = false; int start = 0; int stop = 0; while( ( start = temp.indexOf( replace , stop )) != -1 ) { found = true; stop = start + replace.length(); sb = new StringBuffer( temp.length() + with.length() - replace.length() ); sb.append( temp.substring( 0 , start ) ); sb.append( with ); sb.append( temp.substring( stop , temp.length() )); temp = sb.toString(); stop += with.length() - replace.length(); } if( ! found ){ return str; }else{ return sb.toString(); } } [ nemnesic @ 10.01.2006. 06:48 ] @
e naso sam i ovo...malo razlicito
Code: public static String replace(String source, String pattern, String replace) { if (source!=null) { final int len = pattern.length(); StringBuffer sb = new StringBuffer(); int found = -1; int start = 0; while( (found = source.indexOf(pattern, start) ) != -1) { sb.append(source.substring(start, found)); sb.append(replace); start = found + len; } sb.append(source.substring(start)); return sb.toString(); } else return ""; } [ voxi @ 10.01.2006. 19:06 ] @
Hvala kolega sad cu da vidim sta kaze ovaj kod!
-- No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 267.14.15 - Release Date: 6.1.2006 Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|