How to create file in current directory?
In my JSP-page I tried to create some file in my current project directory but this file is created in C:\jakarta-tomcat-4.0.1\bin directory. I can do it using absolute path but I'd like to use relative path. Please help me.
Thank you in advance.
Qand.
Try this:
String filename = servletContext.getRealPath(request.getContextPath());Then take off the last part (after the last slash) and put on your temporary file name.
It's a thought, anyway...
Similar Messages
-
How to read files from current directory for applet
I have an applet that needs to read some audio files located in its current directory on the server and I just can't seem to figure it out...maybe I am being dumb...any help?
You can use the ListSorter File Adapter Configuration property to sort based on timestamp. Basically add the following property to the inbound JCA file:
<property name="ListSorter"
value="oracle.tip.adapter.file.inbound.listing.TimestampSorterAscending"/>
<property name="SingleThreadModel" value="true"/>
More info see section 4.2.6 in http://docs.oracle.com/cd/E23943_01/integration.1111/e10231/adptr_file.htm -
How to create a file in current directory
hi,
I want to create a file in a current directory, But when i written following
code then it cannot create file, How i will create file in current directory?
Is there anyone who can help me?what will be the solution of this problem?
Please give me solution
String dir=application.getRealPath("/");
int count;
String filename="sample.txt";
out.println(dir+filename);
FileOutputStream fout=new FileOutputStream(filename);
PrintStream p;
p=new PrintStream(fout);
p.print("1");
p.close();with regards
Binahi,
my problem is that my path is ok...but when i open file in this directory then
it cannot open a file, is there anyone who can do it? When a user save data in server from remote
area then what will be path of my code? how i will solve it? please give me
solution.
with regards
bina -
How to create file on application server?
how to create file on application server?
Hi,
The following program illustrates the creation of ifle in app server and reading the file from appli server:
DATA: ITAB LIKE vbakOCCURS 0 WITH HEADER LINE.
PARAMETERS: P_VBELN LIKE VBAP-VBELN.
START-OF-SELECTION.
SELECT *
FROM VBAP
INTO TABLE ITAB
WHERE VBELN = P_VBELN
PERFORM WRITE_DATA.
PERFORM READ_DATA.
*& Form WRITE_DATA
text
--> p1 text
<-- p2 text
FORM WRITE_DATA.
OPEN DATASET 'VBAP_DATA' FOR OUTPUT IN TEXT MODE.
LOOP AT ITAB.
TRANSFER ITAB TO 'VBAP_DATA'.
ENDLOOP.
CLOSE DATASET 'VBAP_DATA'.
CLEAR: ITAB, ITAB[].
ENDFORM. " WRITE_DATA
*& Form READ_DATA
text
--> p1 text
<-- p2 text
FORM READ_DATA.
OPEN DATASET 'VBAP_DATA' FOR INPUT IN TEXT MODE.
DO.
READ DATASET 'VBAP_DATA' INTO ITAB.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
APPEND ITAB.
ENDDO.
CLOSE DATASET 'VBAP_DATA'.
LOOP AT ITAB.
WRITE:/ ITAB-VBELN,
ITAB-POSNR.
ENDLOOP.
ENDFORM. " READ_DATA
If it is helpful rewards points
Regards
Pratap.M -
How to create file menu in the swing?
How to create file menu or any menu in the swing?
Please help me.How to create file menu or any menu in the
swing?
Please help me.By file menu, do you mean where you can choose a file to open or save to? If so, have you had a look at the File Chooser component? If not, please click on the link in the previous sentence to the Sun tutorial.
Good luck
/Pete -
Hello everybody,
It's my first time using Java Card ^_^,I want to create a file and fill the fill with binary data.but i don't know how to create file with APDU commands,so I need help here.
I think that there must be a Manual of the JavaCard's OS in this world,can someone tell me where to download it??
Thanks.
the fllowing is my card:
Samsung S1
Model:TiEx-32J
EEPROM size:32k
Platform Version:OP 2.0.1
Card Manager Status:OP_READY
KMC:40~4F/No derivation
Message was edited by:
AllenHuangIf you look around the forum for a bit, you will see that there is no notion of file systems on JavaCards (lexdabear posted this information less than two hours ago :-)). To store files, you will have to write an applet to hold byte arrays of the required size and handle receiving and sending of these.
As for documentation, you should have a look at the GP (General Platform) specification at http://www.globalplatform.org/, which defines communication between smart cards and other devices, as well as Sun's own JavaCard pages (http://java.sun.com/products/javacard/), which contain several useful resources on JavaCards.
Message was edited by:
Lillesand -
How to create file system datagrid in flex web application
how to create file system datagrid in flex web application
Hi,
Check this out:
http://shigeru-nakagaki.com/flex_samples/FileReference/FileUploadExample2/FileUploadExampl e2.html
Johnny
Please rate answer. -
How to create file form servlet in our virtual directory
hi....
I want to create a file form my servlet in my virtual directory..
my directory name ia vps
it cconatin vps -> WEB-INF -> classes-> servTest
servTest is servlet....
and i want to create file from servTest in vps directory..
actually i am trying to create file but it by default saved in windows/system32 directory.You need to give the absolute path to create the file, if you just give the filename, the file will be created in the working directory which is system32 for Windows.
You could either hardcode it, or you can use ServletContext.getRealPath("/") ( http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String) ) This will return the path on the server's filesystem where your application folder ( under webapps for Tomcat) is located.
NOTE: If you application is in the form of a .war file, this may not work! The server may return a null.
"/" specifies the root i.e., your application's highest level directory. If your application is webapps/vps then getRealPath("/") will return something like C:\Program Files\Apache Group\Tomcat 4.1\webapps\vps -
How can make JFileChooser set current directory to a nethood "\\host"?
hello everyone,
I want to set the JFileChooser's current directory to a nethood named "host".
In the windows file dialog we can type "\\host\n" and we can explore the remote file system if which has sharing items.
I try to use setCurrentDirectory(new File("\\\\host")), JFileChooser does't work. I must step by step explore the host in networkplaces.
Set the host's subdirectory such as "\\\\host\\f1"can work but how can i get a remote host's subdirectory?
thanks for any help.
hu.Valerie Debonair wrote:
1. Is there any easy way to set a an environment variable changing a working directory where a script is being executed? I 'm not so sure if i understood you exactly.
Script can be executed/called only in/at the directory where it is. You can call script from path 'a' even if script's location is in the path 'b' , but you can't execute script with something like $@/dir1/dir2/myscript.sql if the script is realy in /dir1/myscript.sql .
Although for something similiar you can consider using symbolic links if you are on unix/linux.
Environment variables can't be changed and defined from within sqlplus so you will have to define them when you are in the os's command line or related gui where you can do the same. Also you could create env variable that can hold the path to the script so when the script is called , there is no need to write the full path, only variable name.
2. How can I view path environment?path environment.
There is no such thing.
There is path environment VARIABLE . You can view it's contnent by typing echo $path in linux/unix or by typing set path in windows.
regards,
Valeriecheers -
How to create a table with directory which is on different machine
Hi All,
I have two servers one is db server db1 and another is app server app1
I will get files from customer into app1 server in the path d:\files\incoming
I want to create a table with directory (when I create that it will be mapped to db1) which maps to app1\d\files\incoming,
please let me know how to achieve this,NSK2KSN wrote:
Hi All,
I have two servers one is db server db1 and another is app server app1
I will get files from customer into app1 server in the path d:\files\incoming
I want to create a table with directory (when I create that it will be mapped to db1) which maps to app1\d\files\incoming,
please let me know how to achieve this,This is nothing to do with SQL or PL/SQL as such.
The answer lies in the remit of your Windows administrator to create an alias or link that points
from your db server to your app server.
Once that is done, you can refer to the directory as if it was a local one situated on the db server, as normal.
Edited by: Paul Horth on Feb 21, 2013 10:13 AM
Changed Unix to Windows when I noticed the direction of the slashes. -
How to store file into a directory?
i want to save the file(text file) into the directory which i have created using File object in the codes below. how do i do it?
public void saveString(String filename, String string)
//declare textfile to be null
PrintWriter textFile = null;
String line = null;
try {
// writes to write.txt
textFile = new PrintWriter (new FileWriter(filename,true));
line = string;
// save string in textfile
textFile.println(line);
textFile.close();
// create a directory (to store (output).xml file)
File fobj = new File("Testing");
fobj.mkdir();
catch (IOException e) {
System.out.println("Error in opening file");
System.exit(0);
}create the directory first and then create the file u want liek this
File f = new File (fobj,filename);
and then open the fiel to write like this
textFile = new PrintWriter (new FileWriter(f,true));
regards
rohan -
How to pick files from ECC directory
Hi All,
I have to pick files from the directory of ECC. can anyone tell me how to configure the sender File apapter? Can i use NFS for the same?
Regards,
Lavanya RHi Lavanya,
With my knowledge two ways to pick the file from ECC using File adapter.
1. If you use NFS, mount point should be created in ECC for the Directory to access from PI.
2. If you use FTP, FTP ports must be opened between PI and ECC. -
E-mailing report attempts to write temp file in current directory
When e-mailing a report from the previewer, Reports 6.0 attempts to write a temporary file in the current NT directory. This file is the actual e-mail attachment, in this case a PDF file.
Unfortunately the current directory is where the application resides, and therefore users do not have write permission. Is there any way to re-direct where the temporary file is created (i.e. a local drive or the Windows temp directory)?
Thanks in advance.change your registry key entry which says
REPORTS60_TMP to which ever dir you want -
Hi can create files using the code shown in the current working directory of my executable when this.filePath = "atext.xml". But if I change this.filePath ="c:\data\atext.xml" I get an error such as "System cannot find the path specified" true, the path hs not been created, but that is what I am trying to do. What do I need to change.?
try{
String fileName = new String();
fileName = this.filePath;
FileWriter fw = new FileWriter(fileName);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter outFile = new PrintWriter(bw);
outFile.println(emptyXML);
outFile.close();
catch (IOException ioex){
System.out.println(ioex.getMessage());
System.exit(1);Probably the message means that the c:\data directory doesn't exist. You can't create a file in a nonexistent directory, so you would have to create the directory first for that to work.
-
Create folder in current directory
Hi all,
I would like to be able to create a folder through my java program, in the current directory that the java program is in.
Furthermore, I do not want to have to change any code if the java program is suddenly moved to a different folder.
Something like this, but obviously currentDirectory would have to actually be the specific directory that the program is in:File f = new File(currentDirectory);
f.mkDir();Also, just on a side note if anyone has any knowledge of MySQL, I would like to be able to do this when using 'batch mode' and pointing a batch file to a text file containing mysql commands:
mysql -u root -p < d:\mysql\jdbc\createdatabase.txtso the current directory would replace 'd:\mysql\jdbc\'.
thanks very muchHi Jon
On the first topic, try this.
import java.io.File;
public class MakeDir {
public static void main(String[] args) {
if (args.length != 1 || args[0] == null || args[0].trim().length() == 0) {
System.out.println("Usage: java MakeDir <folder name>");
System.exit(-1);
File f = new File(System.getProperty("user.dir") + "\\" + args[0]);
f.mkdir();
}/John
Maybe you are looking for
-
Error message "The printer requires Interventi​on" on Windows 8.1
I have Windows 8.1 and get an error message every time I send a print job. The jobs just sit in the print queue. The message says that intervention is required. We are using the wireless option. We have other computers that run Windows 7 and they
-
How to exclude the overhead cost from DIP source data
Hi : I'm using EK01 condition to catch all the cost booked against the project object from PS, when I try DP91 to have DMR, it's return error "material determination error".. that's caused by overhead cost element is not configred in ODP1. Actually,
-
Help Error (193) After Effects CS5
Hi dear friendsI just installed After effects cs5 and sends me this error and I opened, I was looking for a long time and can not find the solution, but it says the message I give here more info on my pc, and hopefully I can help solve this I do not
-
Can a RAP fallback to a MAP?
Hello all, If the wired connection of a Root Access Point(Cisco 1522AG) goes down, can a RAP fall to a MAP role, find a parent and still offer client connectivity? Thanks, Rares
-
Hi All, I am trying to display euro symbol in firefox/IE browser ,but its getting displayed as ? instead of euro symbol.