import java.io.*;
...
File f = new File( "c:\\new_name.txt" );
if ( f.exists() ) {
/* -- here can be override question */
f.delete();
}
boolean b = new File( "c:\\old_name.txt" ).renameTo( f );
Microsoft AX 2012, X++, C#, SQL server, SSRS, Java, JavaFX, Oracle, PL/SQL, Delphi - codes examples, step-by-step tutorials, experiences.
Showing posts with label java - files. Show all posts
Showing posts with label java - files. Show all posts
Monday, January 22, 2018
JAVA - How to rename file
Friday, December 8, 2017
JAVA - How read text file
Rows are retrived row by row from text file with helping of java.io.BufferedReaded class.
import java.io.*; ... /* -- check if file exists */ File file = new File( "c:\\test2.txt" ); if ( ! file.exists() ) { return; } /* -- read data by rows */ try { BufferedReader in = new BufferedReader( new FileReader( file ) ); try { String s; while ( ( s = in.readLine() ) != null ) { /* -- action with row */ System.out.println( s ); } } finally { /* -- close reader */ in.close(); } } catch ( IOException e ) {}Output could be:
50 51,9940881520819 53,9831973101194 55,9623857448431 57,92678579208 59,8716397322638 ...
Subscribe to:
Posts (Atom)