Renaming a text file
I need to rename a text file in a java application.Can somebody give me a sample code or some ideas on how to do that.
thanks
import java.io.*;
File oldfile = new File("oldfilename");
oldfile.renameTo(new File("newfilename"));
Similar Messages
-
Hello Everyone,
I need to rename a text file to :
YYYYMMDD_HHMMSS_Name_Serial Number
Any T sql for this??
Thanks.
Regards, Kunjay Shahplease refer
http://sqlserverjunction.wordpress.com/2013/04/24/rename-file-using-t-sql/
http://sqlmag.com/t-sql/rename-files-or-directories-fly-t-sql-scripts
vt
Please mark answered if I've answered your question and vote for it as helpful to help other user's find a solution quicker -
Intermittently Text file cannot be opened directly from Finder
One day I would like to duplicate a text file by right click such file to select "Duplicate". However I accidentally pressed "Return" before right click selecting "Duplicate". It means that after pressing "Return", I entered the mode to rename this text file name, but then I continuously to right click selecting "Duplicate".
After that, I saw a duplicated text file with the same name plus "copy" after this name. The file was dim in color. I tried to delete it but Finder disallow me to delete it. Finder told me that it was occupied by other and ask me whether I would like to "Force Delete". Then I clicked yes. Deletion operation was successful.
After that, when I opened the same original text file by directly double click the text file. The operation was failed and Finder output two error window prompt with below two error messages:
"The application can't be found"
"The operation can't be completed
An unexpected error occurred (error code -43)"
After that, I tried to check the information by clicking "Ctrl-I" on this file. By default, I use TextEdit to open text file. I tried to select TextEdit as the default application for all text file in the information window. However, Finder still output above two windows prompt of error messages.
If I tried to open TextEdit or any other editor application first and then open such text file directly from its menu, the text file can then be opened.
Even for files within the same directory, I also cannot directly double click them from Finder to open it. Until I close the Finder window and reopen a new Finder window of such directory, then I can double click to open text file, where it would be opened by my default text editor "TextEdit".
After that, from time to time, such two error message windows will prompt out disallowing me to directly double click opening the text file. For example, originally a text file can be opened properly. After working on the file some time later and try to open the other text file in the same directory, such two message windows will prompt out. Or when I work such text file and the swap to other application, and then go back to Finder to double click such opened text file, such two error message windows will also prompt out. The only way to temporary fix it is to close the Finder window first and reopen it again.
In addition, after such accident, I also discovered that Finder cannot instantly update directory content anymore. For example, I setup FTP server and someone can upload files to my Public directory, and where my Public directory has been opened before anyone ftp files to me, the Public directory cannot update itself after someone uploaded files to me through ftp.
Or sometime I execute copy operation within VMware image to copy a file to shared directory, I also cannot see the directory in Finder update the content. I have to click to other directory and then go back to such shared directory so as to refresh the directory content list. Even I click "Ctrl-R", it cannot refresh the directory.
In the past before such accident, Finder works fine to update directory content promptly after any upload or copy operation.
In addition to bug fix patch, is there any workaround solution I can try to recover my Finder?HI,
This is a shot in the dark but it can't hurt.
Locate these files.
com.apple.finder.plist
com.apple.textedit.plist
~/Library/Preferences
Move those files the Trash and restart your Mac.
If that doesn't do the job, boot from your install disk and check the startup disk for errors.
Insert Installer disk and Restart, holding down the "C" key until grey Apple appears.
Go to Installer menu and launch Disk Utility.
Select your HDD (manufacturer ID) in the left panel.
Select First Aid in the Main panel.
*(Check S.M.A.R.T Status of HDD at the bottom of right panel. It should say: Verified)*
Click Repair Disk on the bottom right.
If DU reports disk does not need repairs quit DU and restart.
If DU reports errors Repair again and again until DU reports disk is repaired.
When you are finished with DU, from the Menu Bar, select Utilities/Startup Manager.
Select your start up disk and click Restart
If the hard disk appears to be ok and you still can't launch Text Edit, back up all important data and perform an Archive & Install.
http://theappleblog.com/2009/08/27/snow-leopard-the-installation-process/
Carolyn -
Renaming Images from Text File
Hello,
I am trying to rename images in a folder to match the names within in a text file. The names in the text file are all unique, so using a rename batch like example-1.jpg, example-2.jpg, etc. won't work. I have matched the structure between both the name and image file, so I need automator to traverse down the text file and add each unique name to the corresponding image.
If anyone has some help for this it will greatly be appreciated! ThanksI wrote you a shell script that will do the job.
First, put all your images into a folder (if you haven't already done so). Make a copy of the folder for safety's sake (I tested the script and it should work fine, but it's always good to have a backup).
Now, make sure each new name in the text file is on its own line. Rename the file to "list.txt" and put it in the same folder as the images (better make a copy of the list, too).
Now, download this file: http://danielrichman.com/tmp/file_rename.sh
Put it in the same folder as your images.
Now, open Applications -> Utilities -> Terminal and type the following (without quotes):
"cd "
Then open up the Finder window that contains the images. In the title bar of the window, there's a little folder icon. Drag the icon into the Terminal window. (You should see the path copied.)
Then, in Terminal, press enter.
Then copy this (and press enter at the end):
"chmod a+x ./file_rename.sh"
Then, do this:
"./file_rename.sh"
That should be it! Please let me know how it goes.
Good luck!
ddr -
Not able to save report output in a text file and RTF file
I am using Oracle Developer6.0 . I am facing problem with reports. I am invoking reports from form using run_product.
1. I could not able to save the report in text file . Whenever i try to save the report output in a text file.It gives dump and application get closed.
2. In RTF format , it execute the query which i have given at the design time while creating a report . But while running i am passing query either through lexical parameter or passing value of where criteria user parameters. It display the output for the specified value. But when i save this report output in rtf file . It execute design time query and save that in a rtf file.
If any body is having any idea about it . Please let me ASAP . It is very urgent for me.
Thanks in advanceTry the following:
Do not generate the report to .rep file, but rename/copy the .rdf file to .rep file and execute it. -
Importing text file (with file names) into Automator.. is it possible?
Hello all,
I have been working with Windows Batch files for my line of work. I have a couple of file names in a text file (a column), which I want to copy from one folder of one hdd to another folder on a different hdd. I have been trying to do this kind of work with a Mac. I already know how you copy and rename files in automator (which isn't difficult, of course) but you have to 'select' the files in the finder first (with get specified items).
But the only way i see that you can specify items is by selecting them... is there a way to import a text file with all the file names instead of selecting all the file names manually?
or is there an AppleScript alternative which I can use to import the text file (or just copy into applescript) and run before the query's of copying and renaming the files? I am kind of new to Apple programming.
The text file looks like this:
image1.jpg
image2.jpg
etc..
so there has to be a command to: 'goto' a specific folder as well.
Thanks in advance!You can import text files, but if they are just names you will need an additional action to add the source folder path. A *Run AppleScript* action can be used, for example:
Tested workflow:
1) *Ask for Finder Items* {Type: files } -- choose the text file containing the names
2) *Combine Text Files* -- this gets the text file contents
3) *Filter Paragraphs* { return paragraphs that are not empty } -- skip blank lines
4) *Run AppleScript* -- copy and paste the following script:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 680; height: 340px;
color: #000000;
background-color: #FFEE80;
overflow: auto;"
title="this text can be pasted into an Automator 'Run AppleScript' action">
on run {input, parameters} -- add folder path
add the specified folder path to a list of file names
input: a list of text items (the file names)
output: a list of file paths (aliases)
set output to {}
set SkippedItems to {} -- this will be a list of skipped items (errors)
set SourceFolder to (choose folder with prompt "Choose the folder containing the file names") as text -- this is the folder containing the names
repeat with AnItem in the input -- step through each name in the input
try
set AnItem to SourceFolder & AnItem -- add the prefix
set the end of the output to (AnItem as alias) -- test
on error number ErrorNumber -- oops
set ErrorNumber to (" (" & ErrorNumber as text) & ")" -- add the specific error number
set the end of SkippedItems to (AnItem as text) & ErrorNumber
end try
end repeat
ShowSkippedAlert for SkippedItems
return the output -- pass the result(s) to the next action
end run
to ShowSkippedAlert for SkippedItems
show an alert dialog for any items skipped, with the option to cancel the workflow
parameters - SkippedItems [list]: the items skipped
returns nothing
if SkippedItems is not {} then
set {AlertText, TheCount} to {"Error with AppleScript action", count SkippedItems}
if TheCount is greater than 1 then
set theMessage to (TheCount as text) & space & " items were skipped:"
else
set theMessage to "1 " & " item was skipped:"
end if
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set {SkippedItems, AppleScript's text item delimiters} to {SkippedItems as text, TempTID}
if button returned of (display alert AlertText message (theMessage & return & SkippedItems) ¬
alternate button "Cancel" default button "OK") is "Cancel" then error number -128
end if
return
end ShowSkippedAlert
</pre>
5) *Copy Finder Items* { To: _your external drive_ } -
Removing first line in text file... Memory and HD concern
Hello all,
I want to remove the first line of a text file. This is easy... One way
to do it, is to find the first "end of line" caracter, strip the string
and re-write the sting in file with the "strip to sreadsheet" VI.
Since the file can be quite large (about 120000 lines), is this a good
way to do it. Will it re-write all the line or just moving the "begin
of file" pointer to the second line? If it re-write the whole file,
this option is not very good since I could have to do this operation
quite often. (I want the file to be a kind of circular buffer / backup).
What do you think is the best way to do this?
Thanks!
VincentI think you would have to read in all the data and write it to a new file, you could either keep the data in RAM or simply write to another file then delete the original, and then rename the temp one. So obviously that is a lot of data and memory.
My main question is are you trying to use a text file as a circular buffer? If so can you tell us more about the data, ie is it strings of a constant length? Does a user ever need to read the file or could we head binary?
A solution would be to truly make the file a binary file, so you could actually seek through the file easier, and maybe make the first data chunk the location of the most recent write. The obvious danger is then writing over existing data. This solution is still risky because of the data writes.
You may want to look at some of the other file formats like HWS which maintains a hierarchy of data for you so you can simply add and remove data from it. However, a user will not be able to easily read it. -
Replacing text in Text File in a perticuler line number
Hi,
I have a text file where values will be stored like
user=alex;checkout=no;checkin=yes;
user=rexy;checkout=yes;checkin=yes;
user=nik;checkout=no;checkin=no;
user=philip;checkout=yes;checkin=no;
user=nex;checkout=yes;checkin=no;
I know the line number of user nik(no=3) how can i replace that full line only with new values
or a particular part (checkout=yes).According to each event i have to change a specific part in text file for that user .
Thanks
[email protected]Read the first two lines and write them to a new file. Write the new values for line 3 to that new file. Read the rest of the lines and write them to that new file. Close all the files, delete the old file, rename the new file.
-
How can i delete a UserName from a text file using Strings or io.
hi i m trainee
i have been assigned to make java program which deletes a UserName and
his Passwor from a Text File
i m unable to do it using the code below
plz help
do reply
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java .applet.*;
import java.io.*;
class Del extends JFrame implements ActionListener
String s2;
JTextField CWDMUserDText = new JTextField();
JButton CWDMSecDelButton = new JButton("DELETE");
JLabel CWDMUserLabel = new JLabel("USER NAME");
JPasswordField CWDMPassDText = new JPasswordField();
JLabel CWDMPassLabel = new JLabel("PASSWORD");
//String user,pass;
/* CONSTRUCTOR*/
Del()
Container contentPane=getContentPane();
contentPane.setLayout(null);
setLocation(400,200);
contentPane.add(CWDMUserDText);
contentPane.add(CWDMSecDelButton);
contentPane.add(CWDMUserLabel);
contentPane.add(CWDMPassDText);
contentPane.add(CWDMPassLabel);
CWDMUserLabel.setBounds(20,70,100,25);
CWDMPassLabel.setBounds(20,100,100,25);
CWDMUserDText.setBounds(150,70,100,25);
CWDMPassDText.setBounds(150,100,100,25);
CWDMSecDelButton.setBounds(80,135,100,25);
CWDMUserDText.addActionListener(this);
CWDMPassDText.addActionListener(this);
CWDMSecDelButton.addActionListener(this);
contentPane.setBackground(Color.CYAN);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
public void actionPerformed(ActionEvent ae)
if(ae.getSource()==CWDMSecDelButton)
// user = CWDMUserDText.getText();
// pass = CWDMPassDText.getText();
// showarr();
s2 = CWDMUserDText.getText();
CWDMUserDText.setText("");
CWDMPassDText.setText("");
DelUser(s2);
public static void main(String args[])
Del myframe1= new Del();
myframe1.setSize(300,200);
myframe1.setVisible(true);
public void DelUser(String s)
//int a;
try
FileReader fr = new FileReader("file.txt");
BufferedReader br = new BufferedReader(fr);
String s1;
int a;
int len = s.length();
System.out.println(len);
//s2 = CWDMUserDText.getText();
while ((s1=br.readLine()) !=null)
if((a=s1.indexOf(s))>0 && (a=s1.indexOf(s))!=0)
System.out.println(a);
fr.close();
catch(FileNotFoundException e)
System.out.println("exception occured");
catch(IOException e)
System.out.println("io");
}Some tips:
1) If you are adding or deleting stuff from a text file you need to write a new, modified file and then, optionally, do something like:
rename the old file to whatever.bak or the like.
rename the new file to the old.
2) Don't depend on System.out so much on a GUI application. For example if you get an exception use javax.swing.JOptionPane to display an alert (and show the message from the exception). You can write the stack trace to System.out if you want.
3) Don't muck about with calculating bounds for screen objects, let a layout manager sort it out. I like BoxLayoutManager for most things like this.
4) For bonus points do your IO in a separate Thread. Generally you don't want anything happening in an actionPerformed method which significantly delays it's return. The method should launch a new Thread to do the job, and disable the button until the Thread finishes. -
HOW TO IMPORT HUNDREDS OF TEXT FILE TO DATABASE AS TABLE
Hi,
I have hundreds of text files in my computer. Every text file includes records. I want to see these records in one table at the database. How can I do that?
thank you very much for help
ömer faruk akyüzlü
in TurkeyI have a standard template that my developers use for reading text files using External Tables . Each developer gets an external table to read in test data. The format the data in CSV format, but you could use others. The External Table points to a generic file name, such as "csv_data". They then just rename the file or create a link to it, depending on the OS.
My solution uses the Directory objects. The following can be put in a script and run passing the first argument as the developers name. It supports a csv file upto 15 columns, but you can expand it.
-- begin script
CREATE OR REPLACE DIRECTORY &1 as '/home/&1';
grant read on directory &1 to public;
alter session set current_schema=&1;
--drop table csv_data;
CREATE TABLE csv_data
col1 VARCHAR2(250),
col2 VARCHAR2(250),
col3 VARCHAR2(250),
col4 VARCHAR2(250),
col5 VARCHAR2(250),
col6 VARCHAR2(250),
col7 VARCHAR2(250),
col8 VARCHAR2(250),
col9 VARCHAR2(250),
col10 VARCHAR2(250),
col11 VARCHAR2(250),
col12 VARCHAR2(250),
col13 VARCHAR2(250),
col14 VARCHAR2(250),
col15 VARCHAR2(250)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY &1
ACCESS PARAMETERS
(RECORDS DELIMITED BY newline
NOBADFILE
NODISCARDFILE
NOLOGFILE
SKIP 0
FIELDS TERMINATED BY ","
OPTIONALLY ENCLOSED BY '"'
RTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
col1 CHAR, col2 char,col3 char,col4 char,col5 char,col6 char,col7 char,col8 char,col9 char,
col10 char,col11 char,col12 char,col13 char,col14 char,col15 char
LOCATION (&1:'csv_data')
REJECT LIMIT Unlimited
NOPARALLEL
NOMONITORING
--end script -
How to rename the XML file generated during payment run
Hi,
We have a requirement to rename the XML file during payment run, format some fields of XML file and upload it onto Application server with the new XML file name. All these activities need to be performed during payment run F110.
Please let know if there is any User exit or Enahancement to achieve these functionalities.
Thanks !
Regards,
RavinderHi,
We have achieved the second functionality also i.e. populating the additional nodes or custom nodes of an extended tree.
This is what we have done...
We have copied the standard exit FM: DMEE_EXIT_TEMPLATE_EXTEND_ABA into a custom one and assigned it to each (custom) node in 'Source' tab. Line item text FPAYP-SGTXT will not be returned via this FM, so we fetched it explicitly from BSEG table using the input FPAYP-DOC2R (this field will have the company code, document number, fiscal year and item no, all concatenated).
Thanks,
/Ravinder -
Not renaming attachment xml file name in receiver mail adapter
Hi,
I receive SOAP from GRC and need send to Partner an email.
I have SOAP to MAIL scenario where an xml file is picked up and transformed and zipped into the target format in XI which has to be sent as an attachement in an email on the receiver side.
I am getting the mail with the attachement. But I would like to rename the attachment as the name "NFE.XML" and the ZIP File as the name "nfe.zip"
I am using MAIL adapter with Modules above.
Number Module Name Module Type Module Key
1 AF_Modules/PayloadSwapBean Local Enterprise Bean Transform
2 AF_Modules/MessageTransformBean Local Enterprise Bean ContentType
3 AF_Modules/PayloadZipBean Local Enterprise Bean zip
4 sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean Local Enterprise Bean mail
Module Configuration :
Module Key Parameter Name Parameter Value
Transform swap.keyName payload-name
Transform swap.keyValue NFE
ContentType Transform.ContentType application/xml; name="NFe.xml"
zip zip.filenameKey ContentType
zip zip.mode zip
I am using transport protocol "XIPAYLOAD" and set "KEEP ATTACHMENTS"
I have with result example above :
Name from ZIP : PayloadName.zipu200E(4KB)u200E
Name from attachment : PayloadName
Regards,
RicardoHi Shobhit,
The module tab of your mail adapter will look like this.
Processing Sequence
Module Name Type Module Key
localejbs/AF_Modules/MessageTransformBean rename LocalEnterpriseBean
sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean mail Local EnterpriseBean
Module Configuration
Module Key Parameter Name Parameter Value
rename Transform.ContentDescription File
rename Transform.ContentDescription attachement;filename="yourfilename.ext"
rename Transform.ContentType application/text;name="yourfilename.ext"
Thanks
Amitanshu -
Add date to new text file name and generic text in body
Okay, I hope this is the right forum. To help manage and keep track of incoming assets/files and I created an Automator workflow with the following: "Get Selected Finder Items → Get Folder Contents → New Text File (w/Show this action when the workflow runs so I can give a unique name).
This creates a text file with the folder contents listed in the body.
I would like to know if I can do two things:
1. Automatically add a date/time stamp to the Save as field so it will automatically have a unique file name?
2. I also want to add text before the listed contents within the text file. (e.g.: Let's say the folder contents are Volumes/Mac HD/Generic_movie.mov. I want the final text to read:
"The following file has been moved to the local volume at: Volumes/Mac HD/Generic_movie.mov"
Is there a way to accomplish either one or both of these with Automator or AppleScripts?
Thanks.I would like to know if I can do two things...
This might address your first concern:
*1) Get Selected Finder Items*
*2) Get Folder Contents*
*3) New Text File* -- select a destination folder and check *Show Action When Run*
*4) Rename Finder Items:*
Choose *Add Date or Time* from the popup
Date/Time: select Created, Modified, or Current - Format: *Month Day Year*
Where: *After name* - Separator: *Forward Slash*
Separator: Space - check *Use Leading Zeros* (optional)
*5) Rename Finder Items:*
Choose *Add Text* from the popup
Add: *" at"* -- put a leading space before "at" (without the quotes), and select *after name*.
*6) Rename Finder Items:*
Choose *Add Date or Time*
Date/Time: Current - Format: *Hour Minute Second*
Where: *After name* - Separator: Dash
Separator: Space - check *Use Leading Zeros* (strongly recommended)
+--- End of Workflow ---+
Save the workflow as an application and use it as a droplet. Drop a desired folder onto the saved applet and enter a name when the dialog appears. The new text file, which will be found in the destination folder, should be appended with a date and time stamp, e.g., *"My Folder List 7/8/2010 at 23-54-09"*
Tested using Mac OS 10.4.11 and Automator v. 1.0.5
Good luck; hope this helps. -
Can we store procedure in a folder in text file using SQL QUERY
I want to create a folder in D drive and give folder name as current date. After that create no. of text files based on how many procedure are, text file name will be same as procedures name and insert a procedures inside the text files by using stored
procedure.I want to create a folder in D drive and give folder name as current date. After that create no. of text files based on how many procedure are, text file name will be same as procedures name and insert a procedures inside the text files by using stored
procedure.
You can use generate scripts wizard for this. It will by default give scripts in .sql format. You can then use a command line script to change all of them to .txt.
Another option is to have SSIS package and use File SYstem Task to rename it to .txt
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Best way to handle text files in OD10g
We have a requirement to store reports in text format into a database field, to be able to view the reports, and to print them if desired using Forms 10g. What is the best way to handle this?
- define the field in the database as clob or blob?
- if CLOB is the choice, what tools to use to upload CLOBs to the database (since webutil transfer is for blob only)?
- in Forms 10g, can one use the Forms data type LONG for CLOB?
- can you do Forms search on clob and blob fields?
- how can reports that are stored in fields be viewed without first downloading to the client workstation?
- in Forms 10g, what is the best way to view text files residing in local PCs: "host notepad myFile"?
Thanks much for your reply!
gkTake a deep breath. Relax. All is fine.
iDVD does not look at the size of your video file, it looks at the length. iDVD can accomodate up to 2 hours of movie
iDVD gives you different options depending on the length of your movie. Although I won't agree with your friend about reducing the length of your movie to 15 minutes, if you could trim out a few minutes to get it under an hour that setting in iDVD (Best Performance though the new version may have renamed it) gives you the best quality. Still, any iDVD setting will give you good quality even at 64 minutes
In FCE export as Quicktime Movie NOT any flavour of Quicktime Conversion. Select chapter markers if you have them. If everything is on one system unchecked the Make Movie Self Contained button. Drop the QT file into iDVD
Maybe you are looking for
-
Downloads open as Text Edit files
Hi, I bought my first Mac a couple of weeks ago (never been able to afford one before!) and it's proving to be as amazing as I expected, but I'm still trying to work lots of things out. When I try to download files from the internet or from email att
-
Possible to draw 1/2 in OSX? as in HALF, a smaller font?
I know some programs you can input 1/2 and it becomes smaller to emphasize one half. Please advise. Thanks
-
HT5467 Why is my default camera app not appearing in the location list?
Any photo taken by the native camera app in ios6 (after a restore from ios5.1 to ios6) no longer includes gpsinfo. The default camera never asked for permission, nor is it found in the location data list under privacy settings. Even resetting the pri
-
hi friends i have a oracle table for country,city,town. this table is like a tree and it has 5000+ rows and has relation with some other tables this datas fill into dropdown(combobox)if user select county from combobox1 ,combobox2 fill with this coun
-
Pixelpost and Personal Web Sharing in Tiger
Dear Friends: I figured out how to install Pixelpost (for a photoblog) in my OS X Tiger system -- by using MAMP. I changed the Document Root in MAMP so that now it looks to the Personal Web Sharing folder in the Mac (the Sites folder in the /usr/ spa