Trouble reading 2 files on server
I have the code written to upload a file to the server. I want to be able to upload 2 files to the server with the same socket connection. Any ideas how to do this? Also when i upload the file it doesn't always send the whole file. Any ideas why this is happening and how i can fix this? I'll post the code I have below.
import java.io.IOException;
import java.net.ServerSocket;
public class Server {
* @param args
* @throws IOException
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
ServerSocket serverSocket = null;
boolean listening = true;
try {
serverSocket = new ServerSocket(12345);
} catch (IOException e) {
System.err.println("Could not listen on port: 12345.");
System.exit(-1);
while (listening)
new ServerThreads(serverSocket.accept()).start();
serverSocket.close();
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
public class ServerThreads extends Thread {
private Socket socket = null;
ServerUtil archUtil = new ServerUtil();
public ServerThreads(Socket socket) {
// TODO Auto-generated constructor stub
this.socket = socket;
public void run() {
try{
BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
if(rd.readLine().equals("file")){
archUtil.generateTmpDir();
archUtil.uploadFile(socket,rd);
else
System.out.println("this is some crap");
catch(IOException e){
System.out.println("is this you that's given me a problem");
public class ServerUtil {
String tmpDir;
String fileName;
Process proc;
Runtime runtime = Runtime.getRuntime();
public static final int BUFFER_SIZE = 1024 * 50;
private byte[] buffer;
public ServerUtil() {
// TODO Auto-generated constructor stub
public void generateTmpDir(){
java.util.Date d = new java.util.Date();
long off = (long) Math.random();
GregorianCalendar todaysDate=new GregorianCalendar();
int hour,mins,secs;
hour=todaysDate.get(Calendar.HOUR);
mins = todaysDate.get(Calendar.MINUTE);
secs = todaysDate.get(Calendar.SECOND);
String SECS = java.lang.Integer.toString(secs);
String HOUR = java.lang.Integer.toString(hour);
String MINS = java.lang.Integer.toString(mins);
String time = HOUR + MINS + SECS;
/** Unique String Name created **/
String RANDOM_OFFSET = new String ();
RANDOM_OFFSET =time + d.hashCode() + RANDOM_OFFSET.hashCode()+ off;
setTmpDir(RANDOM_OFFSET);
boolean success = (new File("tmp/" + RANDOM_OFFSET)).mkdir();
if (!success) {
// Directory creation failed
/**try {
proc = runtime.exec("mkdir tmp/" + getTmpDir() );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public void uploadFile(Socket socket, BufferedReader rd){
buffer = new byte[BUFFER_SIZE];
System.out.println("accepted Socket");
try {
BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
setFileName(rd.readLine());
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmp/" + getFileName()));
int len = 0;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
System.out.print("#");
in.close();
out.flush();
out.close();
socket.close();
System.out.println("\nDone!");
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
* @return the tmpDir
public String getTmpDir() {
return tmpDir;
* @param tmpDir the tmpDir to set
public void setTmpDir(String tmpDir) {
this.tmpDir = tmpDir;
* @return the fileName
public String getFileName() {
return fileName;
* @param fileName the fileName to set
public void setFileName(String fileName) {
this.fileName = fileName;
public class Network {
public static final int BUFFER_SIZE = 1024 * 50;
private byte[] buffer;
public Network() {
// TODO Auto-generated constructor stub
buffer = new byte[BUFFER_SIZE];
public void sendFile(String fileLocation, String filename) throws Exception {
Socket socket = new Socket("localhost", 12345);
PrintWriter pout = new PrintWriter(socket.getOutputStream(), true);
pout.println("file");
pout.println(filename);
BufferedInputStream in =
new BufferedInputStream(
new FileInputStream(fileLocation));
BufferedOutputStream out =
new BufferedOutputStream(socket.getOutputStream());
int len = 0;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
System.out.print("#");
in.close();
out.flush();
out.close();
socket.close();
System.out.println("\nDone!");
* @param args
* @throws Exception
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Network nw = new Network();
nw.startClient();
}
multiple crosspost answered elsewhere, Networking I think
Similar Messages
-
Hi,
When i try to read file from server,the following message is displayed .
ORA-29532: Java call terminated by uncaught Java exception: java.security.AccessControlException: the Permission (java.io.FilePermission /tmp read) has not been granted to EWMTRACKTEST. The PL/SQL to grant this is dbms_java.grant_permission( 'EWMTRACKTEST', 'SYS:java.io.FilePermission', ' /tmp', 'read' )
ORA-06512: at "EWMTRACKTEST.GET_DIRLIST_EWM", line 1
ORA-06512: at line 1
thanks and regards
P Prakashit seems obvious, user EWMTRACKTEST doesn`t have access to directory /tmp and the file under that.
try to give read permission and try again.
you could use command line like 'chmod' to grant permissions. -
How to read file from server if I have a logical file path?
Hi guys,
I'm having a pretty "on the run" question,
My program is currently reading a file from server using "open dataset" with file path like this (just example)
/usr/interface/abc/bcd/testfile.dat
Now I got a requirement to make it more consistent to read files, instead of reading that physical file name, I should read the files from a specific folder using logical path.
So I go to T code "FILE" and created a logical path called ZABC_FILE_PATH, unix compatible, with physical path is (for example),
/usr/interface/<sysid>/<client>/<filename>
My question is, can I still use open dataset statement to read this? if yes, how do I do that? If no, there should be alternative way, please let me know what you think. Thanks,Thanks all, I figured it out.
ONe thing is that typo double quote
The other thing is the importing part, I need the full file path.
CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
EXPORTING
CLIENT = SY-MANDT
logical_path = 'ZABC_MY_LOGICAL_FILE_PATH'
* OPERATING_SYSTEM = SY-OPSYS
* PARAMETER_1 = ' '
* PARAMETER_2 = ' '
* PARAMETER_3 = ' '
* USE_BUFFER = ' '
file_name = v_1
* USE_PRESENTATION_SERVER = ' '
* ELEMINATE_BLANKS = 'X'
IMPORTING
FILE_NAME_WITH_PATH = v_what_I_need
* EXCEPTIONS
* PATH_NOT_FOUND = 1
* MISSING_PARAMETER = 2
* OPERATING_SYSTEM_NOT_FOUND = 3
* FILE_SYSTEM_NOT_FOUND = 4
* OTHERS = 5
I really appreciate your contributions, thanks again! -
How to read files on server from a java program?
Hello,
I am fairly new to JSP programming. I have an issue with reading files. I am trying to call method of a normal java file from a jsp program. The method I am trying to call does some IO operation on Files. I have the files in the same directory as my class files on server that is in WEB-INF/classes folder. In my java program, I am giving just the file name to open because the files and the classes are in the same directory. But this is not working.
What exactly should I do to read a file from a java program, that is running on the server?
Any help is appreciated.
Thanks,
KrishnaString realFilePath = application.getRealPath("/WEB-INF/myFile.txt");
File fileToOpen = new File(realFilePath);
out.println(fileToOpen.getAbsolutePath() + ": exists? " + fileToOpen.exists());in this case "application" is a reference to the ServletContext.
It is an implicit variable in a JSP. In a servlet:
ServletContext application = getServletConfig().getServletContext(); -
How to read file at server? URGENT
hi,
I got stucked to read a file which is at the server, i used this code :
java.io.FileInputStream fis;
String ipaddr="";
int ch;
try
fis=new java.io.FileInputStream("server.ini");
while((ch=fis.read())!=-1)
ipaddr=ipaddr+(char)ch;
ipaddr=ipaddr.trim();
System.out.println(ipaddr);
}catch(Exception e){System.out.println(e);}
I'm getting a FileNotFound exception, where i went wrong.Hello hikiran.
The server.ini file should reside in your application working directory. If it's not there, then the JVM won't find it. Otherwise you could specify an absolute path to the file, but your application will be less portable. Another choice you have is to define an environment variable which tells your app where the server.ini file resides, with the command
java -Dmyapp.ServerIni=C\SomeFolder\server.ini myappThen you retrieve the pathname with:
String path = System.getProperty("myapp.ServerIni");This way your app does not depend on the filesystem on which it's been installed to, because changing the command line that starts your app will be enough to have it working.
Note: if you have to read a text file consider using the java.io.BufferedReader class which lets you to get rid of the different text file formats problems you find when you move to a unix like platform (newline characters are different). -
Unable to read file from application server
Hi guys,
I am reading file(could be any extension) from application server,but some time i am successfuly able to read file and sometime unable to read,why its happening .
my code is here
OPEN DATASET E_FILE FOR INPUT IN BINARY MODE . "
IF SY-SUBRC = 0.
DO .
READ DATASET E_FILE INTO GS_PDF_TAB.
IF SY-SUBRC = 0.
APPEND GS_PDF_TAB TO GT_PDF_TAB.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET E_FILE.
ENDIF.
Thanks
Ankur SharmaHi,
What actually happens? Do you get a short dump? Do you get a return code ne 0? Does it run fine but you get no data in your table?
We aren't mind-readers and can't help much without more information.
Try using transaction AL11 to see if you access the files you are trying to open.
Gareth. -
Uploading and reading file from application server
Hi
My problem is when am uploading a file to application server it is getting stored in
usr/sap/transyp1/prod/in directory
after that i want to read that file from application server to update database
when using below code it is showing some other directory in f4 help
DATA: lv_hostname TYPE msxxlist-name.
DATA: lv_server TYPE bank_dte_jc_servername.
PARAMETERS: p_file TYPE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'BANK_API_SYS_GET_CURR_SERVER'
IMPORTING
e_server = lv_server.
lv_hostname = lv_server.
CALL FUNCTION 'F4_DXFILENAME_4_DYNP'
EXPORTING
dynpfield_filename = 'P_FILE'
dyname = sy-cprog
dynumb = '1000'
filetype = 'P'
location = 'A'
server = lv_hostname.
experts could you please help me out
Thanks & Regards
Nagesh.ParuchuriUser Transaction file. You will get all logical file path names.
used following fucntion module to read file name and use command open dataset to read the file.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
CLIENT = SY-MANDT
LOGICAL_FILENAME = C_LOGICAL_FILENAME
OPERATING_SYSTEM = SY-OPSYS
PARAMETER_1 = P_IN_FILENAME
IMPORTING
FILE_NAME = P_OUT_FILENAME
EXCEPTIONS
FILE_NOT_FOUND = 1
OTHERS = 2.
OPEN DATASET P_OPEN_FILE ENCODING UTF-8 IN TEXT MODE FOR OUTPUT.
IF SY-SUBRC <> 0.
MESSAGE E000(38) WITH 'Error in Opening file: ' V_PHY_FILENAME.
ENDIF. -
Open Data Set Error while trying to read file from non SAP server
Hi all,
is it possible to read data from non-SAP application Sever?
I'm using OPEN DATASET p_filin FOR INPUT IN LEGACY TEXT MODE CODE PAGE '1504',
Where p_filin is other Windows server.Our applicition server is under Unix.Is it a problem?
I make test to read file from SAP application server and it was ok.So how to call other server?
Thanks!Hi,
Yes it is possible to read data from a non SAP server through the statement OPEN DATASET.
The important thing to check is that the SAP Server got enough access to the non SAP server so it can perform a reading/writing process depending on your needs.
You should contact your network administrator and BASIS to help you check the permissions. This can be pretty tricky, specially if the servers are in different domains.
Regards,
Gilberto Li -
Not able to read the wsdl file from server Premature EOF encounter
Hi All,
I am facing issue while accessing a web Service from server. Here is the clear view about it.
I created a simple SyncBpel process in a composite and deployed in to the server and it is working fine. Later i created a new Asyn bpel process in a composite and in the external reference i dragged a web Service and imported the wsdl url from server of the SyncBpel and wired the Asynbpel process to webserive .
Now here i am facing peculiar behavior which i am not able to trace it out.
1) For the first time when i import the url of syncBpel from the server i am not facing any error and it is working fine as expected but when i close the Jdeveloper and open it i am not able to user the web Service and it is saying as "Not able to read the wsdl file from server Premature EOF encounter"
2)When i close and open the Jdeveloper i can see the url of the wsdl which imported in webserver is changing from http://stcfmw03.satyam.com:8021/soa-infra/services/Tarak/synchronousBpel/bpelsync_client_ep?WSDL to http://stcfmw03.satyam.com:8021/soa-infra/services/Tarak/synchronousBpel/BPELsync.wsdl
3)when I open and see the url http://stcfmw03.satyam.com:8021/soa-infra/services/Tarak/synchronousBpel/bpelsync_client_ep?WSDL I can see the soap address as *<soap:address location="http://stcfmw03.satyam.com:8021/soa-infra/services/Tarak/synchronousBpel!1.0*soa_5cfb8416-c106-40a2-a53b-9054bbe04b9c/bpelsync_client_ep"/>*
I don’t understand why the soap end contains “*soa_5cfb8416-c106-40a2-a53b-9054bbe04b9c” and this kind of url for soap address is coming to all the bpel process which I am deploying in the server.
I checked the in Jdeveloper where webproxy is uncheck and the server is also up but still I am facing issue of reading the error.
Can someone please help in resolving the issue.
I am using SOA 11g 11.1.1.5 and Jdeveloper 11.1.1.5
Many thanks.
Tarak
Edited by: user11896572 on Jan 17, 2012 5:22 PMHi,
Setting default from the jdeveloper -
During composite deployment from Jdeveloper (wizard driven), you will be given an option to choose the version of the composite and there will also be an option for you to choose if the composite needs to be deployed as default.
Setting default from the em console -
After deploying a composite, login to the em console and click on the composite that you want to set as default, and you will find a tab - "Set as Default". please note that this tab will not be seen, if the composite is already set as default.
Refer -
http://docs.oracle.com/cd/E12839_01/integration.1111/e10226/soacompapp_mang.htm
8.2 Managing the State of Deployed SOA Composite Applications
Thanks -
Error while reading a file from server
Mine is 9i database and 11.5.10.2 oracle apps server
I am trying to read PDF file from server, I used the below code
l_bfile:=bfilename('\u05\app\applmgr\11i\oraclecomn\admin\out\jamuna_server','o7742576.out');
if DBMS_LOB.FILEEXISTS(l_bfile) = 1 then
dbms_output.put_line( 'Exists!');
dbms_output.put_line(dbms_lob.getlength(l_bfile));
else
dbms_output.put_line( 'Not Exists!');
end if;
i used forward slashes (/) instead of backward slashes (\) too and i also made dbms_output.put_line(to_char(dbms_lob.getlength(l_bfile)));
while using dbms_log package , i got the below error .I am bit worried since I have created directory and gave sufficicent priviliges too.
Error report:
ORA-00604: error occurred at recursive SQL level 1
ORA-01460: unimplemented or unreasonable conversion requested
ORA-06512: at "SYS.DBMS_LOB", line 485
ORA-06512: at line 24
I am sure bfilename('\u05\app\applmgr\11i\oraclecomn\admin\out\jamuna_server','o7742576.out') is give BFILE which is empty.
Can you please suggest me what I can do to move further? what kind of priviliges it requires to point and read the file from server?
Please help me in this.
Thanks in advanceI suspect you are not using a directory object is the problem.
Here is the formal description of bfilename
http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/functions12a.htm#SQLRF00610
Sybrand Bakker
Senior Oracle DBA -
Reading a CSV file from server
Hi All,
I am reading a CSV file from server and my internal table has only one field with lenght 200. In the input CSV file there are more than one column and while splitting the file my internal table should have same number of rows as columns of the input record.
But when i do that the last field in the internal table is appened with #.
Can somebody tell me the solution for this.
U can see the my code below.
data: begin of itab_infile occurs 0,
input(3000),
end of itab_infile.
data: begin of itab_rec occurs 0,
record(200),
end of itab_rec.
data: c_comma(1) value ',',
open dataset f_name1 for input in text mode encoding default.
if sy-subrc <> 0.
write: /, 'FILE NOT FOUND'.
exit.
endif.
do
read dataset p_ipath into waf_infile.
split itab_infile-input at c_sep into table itab_rec.
enddo.
Thanks in advance.
SunilSunil,
You go not mention the platform on which the CSV file was created and the platform on which it is read.
A common problem with CSV files created on MS/Windows platforms and read on unix is the end-of-record (EOR) characters.
MS/Windows usings <CR><LF> as the EOR
Unix using either <CR> or <LF>
If on unix open the file using vi in a telnet session to confirm the EOR type.
The fix options.
1) Before opening the opening the file in your ABAP program run the unix command dos2unix.
2) Transfer the file from the MS/Windows platform to unix using FTP using ascii not bin. This does the dos2unix conversion on the fly.
3) Install SAMBA and share the load directory to the windows platforms. SAMBA also handles the dos2unix and unix2dos conversions on the fly.
Hope this helps
David Cooper -
Dynamically Reading Files From Application Server
Hi Experts,
Presently I have to write a program which reads files from the application server dynamically. This program will be scheduled in the background with the frequency of half an hour.
I am Using the function module
CALL FUNCTION 'SUBST_GET_FILE_LIST'
EXPORTING
DIRNAME = '/usr/sap/xxx/xxx/'
FILENM = 'DATASET'
PATTERN = '.txt'
TABLES
FILE_LIST = IT_FILELIST
I am facing problem in specifying the parameter FILENM in the function module,
As I have to read many files from the apps server. How to assign the parameter of function module so it can take the many files generated in the apps server.
Thanks in Advance,
Regards,
Irfan HussainHi,
Instead of the above FM, you can use the following code :
AT SELECTION-SCREEN ON VALUE-REQUEST FOR po_ifile.
PERFORM get_current_directory USING 'PO_IFILE' po_ifile
rov-home_dir rov-curr_dir.
PERFORM get_filename-of-server TABLES itab_filename
USING rov-curr_dir rov-gen_name.
PERFORM help_values_get_with_table_ext TABLES itab_filename
USING rov-curr_dir
po_ifile.
*& Form get_current_directory
text
-->P_0023 text
-->P_PO_IFILE text
-->P_ROV_HOME_DIR text
-->P_ROV_CURR_DI text
-->P_CALL text
-->P_FUNCTION text
-->P_0029 text
-->P_IMPORTING text
-->P_FILE_NAME text
-->P_= text
-->P_PO_IFILE text
FORM get_current_directory USING _fieldname
_filename
homedir
currdir.
IF _fieldname <> space.
PERFORM dunp_value_read USING _fieldname _filename.
ENDIF.
IF _filename = space.
currdir = homedir.
ELSE.
rov-work_dir = _filename.
rov-fdpos = STRLEN( rov-work_dir ).
DO.
IF rov-fdpos = 0.
EXIT.
ENDIF.
rov-fdpos = rov-fdpos - 1.
ASSIGN rov-work_dir+rov-fdpos(1) TO <rov_p>.
IF <rov_p> = rov-delchar.
<rov_p> = space.
EXIT.
ELSE.
<rov_p> = space.
ENDIF.
ENDDO.
currdir = rov-work_dir.
ENDIF.
ENDFORM. " get_current_directory
*& Form get_filename-of-server
text
-->P_ITAB_FILENAME text
-->P_ROV_CURR_DIR text
-->P_ROV_GEN_NAME text
FORM get_filename-of-server TABLES nametab STRUCTURE itabfilename
USING _dirname _genname.
CALL 'C_DIR_READ_FINISH' " just to be sure
ID 'ERRNO' FIELD rov-errno
ID 'ERRMSG' FIELD rov-errmsg.
CALL 'C_DIR_READ_START' ID 'DIR' FIELD _dirname
ID 'FILE' FIELD _genname
ID 'ERRNO' FIELD rov-errno
ID 'ERRMSG' FIELD rov-errmsg.
IF sy-subrc <> 0.
EXIT.
ENDIF.
REFRESH _nametab.
DO.
CLEAR _nametab.
CALL 'C_DIR_READ_NEXT' ID 'TYPE' FIELD _nametab-type
ID 'NAME' FIELD _nametab-name
ID 'LEN' FIELD _nametab-len
ID 'OWNER' FIELD _nametab-owner
ID 'MTIME' FIELD _nametab-mtime
ID 'MODE' FIELD _nametab-mode
ID 'ERRNO' FIELD _nametab-errno
ID 'ERRMSG' FIELD _nametab-errmsg.
_nametab-dirname = _dirname.
MOVE sy-subrc TO _nametab-subrc.
CASE sy-subrc.
WHEN 0.
IF _nametab-name+0(1) = '.'.
ELSE.
APPEND _nametab.
ENDIF.
WHEN 1.
EXIT.
WHEN OTHERS. " SY-SUBRC >= 2
EXIT.
ENDCASE.
ENDDO.
CALL 'C_DIR_READ_FINISH' " just to be sure
ID 'ERRNO' FIELD rov-errno
ID 'ERRMSG' FIELD rov-errmsg.
ENDFORM. " get_filename-of-server
*& Form help_values_get_with_table_ext
text
-->P_ITAB_FILENAME text
-->P_ROV_CURR_DIR text
-->P_PO_IFILE text
FORM help_values_get_with_table_ext TABLES _filename
STRUCTURE itab_filename
USING _currdir
_selfile.
TYPES: BEGIN OF f4typ_head_struc,
tabname LIKE help_info-tabname,
fieldname LIKE help_info-fieldname,
head_text LIKE shstruc-keyword,
END OF f4typ_head_struc.
DATA itab_fields LIKE TABLE OF help_value WITH HEADER LINE.
DATA itab_selvals LIKE TABLE OF help_vtab WITH HEADER LINE.
DATA itab_values LIKE TABLE OF rlgrap-filename WITH HEADER LINE.
DATA itab_header TYPE TABLE OF f4typ_head_struc WITH HEADER LINE.
REFRESH itab_fields.
REFRESH itab_selvals.
REFRESH itab_values.
REFRESH itab_header.
itab_fields-tabname = 'PS0192'.
itab_fields-fieldname = 'BAA01'.
itab_fields-selectflag = ' '.
APPEND itab_fields.
itab_fields-tabname = 'RLGRAP'.
itab_fields-fieldname = 'FILENAME'.
itab_fields-selectflag = 'X'.
APPEND itab_fields.
LOOP AT _filename.
itab_values = itab_filename-type.
APPEND itab_values.
itab_values = itab_filename-name.
APPEND itab_values.
ENDLOOP.
CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE_EXT'
EXPORTING
CUCOL = 0
CUROW = 0
DISPLAY = ' '
FIELDNAME = ' '
TABNAME = ' '
TITLE_IN_VALUES_LIST = ' '
SHOW_ALL_VALUES_AT_FIRST_TIME = ' '
USE_USER_SHRINKING = ' '
titel = _currdir
NO_SCROLL = ' '
NO_CONVERSION = ' '
NO_MARKING_OF_CHECKVALUE = ' '
IMPORTING
index = rov-index
select_value = rov-selvalue
TABLES
fields = itab_fields
select_values = itab_selvals
valuetab = itab_values
HEADING_TABLE =
EXCEPTIONS
field_not_in_ddic = 1
more_then_one_selectfield = 2
no_selectfield = 3
OTHERS = 4.
IF sy-subrc = 0.
CLEAR itab_filename.
READ TABLE itab_filename INDEX rov-index.
IF itab_filename-type+0(3) = 'dir'.
CONCATENATE _currdir rov-delchar rov-selvalue rov-delchar
INTO _selfile.
ELSE.
CONCATENATE _currdir rov-delchar rov-selvalue INTO _selfile.
ENDIF.
ENDIF.
ENDFORM. " help_values_get_with_table_ext
Best regards,
Prashant -
How to read a PDF file from server
Hi All,
I am strucked while creating new file instance .
Here i know the URL.
How to create the File instance by using this URL.
I tried the following way:
URI uri = url.toURI();
File f = new File(uri);
Here i got the following exception :
<code>
Exception in thread "main" java.lang.IllegalArgumentException: URI scheme is not "file"
</code>
Can any one help me?
Thanks in advance......Can any one help me how can i down load a file
from server by using URL?RTFAPI. Url.openStream(). -
Uploading csv files and reading them from server
I want to read a csv file.From Flex i am able to select the
file but when i pass it to the server using struts
FileUploadInterceptor , am not able to pass the file to the
server.FileUploadInterceptor in struts2 processes the request only
if its instance of MultiPartRequestWrapper.Is there any way in Flex
where i can pass the request as a instance of this.Is there any
other way in which i can read the file from the server after
uploading it through flex.Code is as follows :
1)MXML File :
?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import ImportData;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.events.IOErrorEvent;
[Bindable] var fileRef:FileReference = new FileReference();
private function openFileDialog():void{
fileRef.addEventListener(Event.SELECT, selectHandler);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA
,uploadCompleteHandler);
fileRef.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
try{
var textTypes:FileFilter = new FileFilter("Text Files
(*.txt,*.csv)","*.txt;*.csv");
var allTypes:Array = new Array(textTypes);
//var success:Boolean = fileRef.browse();
var success:Boolean = fileRef.browse(allTypes);
catch(error:Error){
trace("Unable to browse for files.");
private function onIOError(event:IOErrorEvent):void {
trace("In here"+event.text);
trace("In here"+event.toString());
// when a file is selected you upload the file to the upload
script on the server
private function selectHandler(event:Event):void{
//var request:URLRequest = new URLRequest("/importAction");
var request:URLRequest = new URLRequest("
http://localhost:8080/pack1/importAction.action");
try
fileRef.upload(request);
catch (error:Error)
trace("Unable to upload file.");
private function completeHandler(event:Event):void{
trace("uploaded");
// dispatched when file has been uploaded to the server
script and a response is returned from the server
// event.data contains the response returned by your server
script
public function uploadCompleteHandler(event:DataEvent):void
trace("uploaded... response from server: \n" +
String(event.data));
]]>
</mx:Script>
<mx:Button label="Import" id="importBtn"
click="openFileDialog()" height="20" width="90"
styleName="buttonsOnSearchBar"/>
<mx:ComboBox x="23" y="44" borderColor="#ff0000"
themeColor="#ff0000"></mx:ComboBox>
</mx:Application>
2)struts.xml file
<struts>
<package name="pack1"
extends="struts-default,json-default">
<global-results>
<result name="error" type="json"></result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error"
exception="java.lang.Throwable"/>
</global-exception-mappings>
<action name="importAction"
class="routing.ImportAction">
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="basicStack"/>
<result name="success" type="json"></result>
</action>
</package>
</struts>
3)Action Class
package com.om.dh.orderrouting.action;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import org.apache.log4j.Logger;
import com.opensymphony.xwork2.ActionSupport;
public class ImportAction extends ActionSupport{
private String contentType;
private File upload;
private String fileName;
private String caption;
private static final Logger logger =
Logger.getLogger(ImportAction.class);
@Override
public String execute() throws Exception {
* Read File Line by Line.. If the file has more than one
word separated by comma
* return error.
ArrayList<String> symbolList = new
ArrayList<String>();
try{
BufferedReader reader = new BufferedReader(new
FileReader(upload));
String line =null;
String symbol=null;
while((line=reader.readLine())!=null){
StringTokenizer tokenizer = new StringTokenizer(line,"\t");
symbol = tokenizer.nextToken();
if(symbol!=null) symbol = symbol.trim();
if(symbol.length()>0)
symbolList.add(symbol);
}catch(FileNotFoundException fne){
if(logger.isDebugEnabled())
logger.debug("File NotFount ", fne);
for(String symbol1:symbolList)
System.out.print(symbol1+" ");
return SUCCESS;
public String getUploadFileName() {
return fileName;
public void setUploadFileName(String fileName) {
this.fileName = fileName;
public String getUploadContentType() {
return contentType;
public void setUploadContentType(String contentType) {
this.contentType = contentType;
public File getUpload() {
return upload;
public void setUpload(File upload) {
this.upload = upload;
public String getCaption() {
return caption;
public void setCaption(String caption) {
this.caption = caption;
public String input() throws Exception {
return SUCCESS;
public String upload() throws Exception {
return SUCCESS;quote:
Originally posted by:
ived
tried this but does not work...
var request:URLRequest = new URLRequest("
http://localhost:8080/pack1/importAction.action");
request.contentType="multipart/form-data";
in the interceptor it expects the request to be instanceof
MultiPartRequestWrapper...
Further the document says that FileReference.upload() and
FileReference.download() methods do not support the
URLRequest.contentType and URLRequest.requestHeaders parameters.
Any help ?? -
I'm being shown an error pop-up message periodically saying "There was a problem connecting to the server. URLs with the type 'file:' are not supported." I have a brand new MacBook Pro, and at no time am I actually having trouble connecting to the server, but this message continues to pop-up several times a day at random intervals. Is there something I'm doing wrong? Or is my computer just having a glitch? Other than that, and a mildly sticking caps lock button, it's working perfectly.
Thank you!Alright it didn't solve it. Any other suggestions?
I haven't suggested a solution yet. I want to know whether you still get the messages while Time Machine is disabled. Do you? If so, try any or all of the solutions proposed in this thread:
There was a Problem connecting to the...: Apple Support Communities -
How to read and write to file on server
can any body tell how to read or write to a file on server, like where do i keep the file and what does the path look like......on server
stand alone i am reading and writing into file but when it comes to server i am confused how it works...i mean the path
thank youThe Path needs to be absolute:
For example in Unix it would look like:
/usr/paz/Test.txtIn Windows it would look like:
C:/Paz/Test.txtHope this helps.
Thanks and regards,
Pazhanikanthan. P
Maybe you are looking for
-
How can I back up only selected files using Time Machine?
I'm a graphic designer, I use a number of Time Capsules to periodically back up my entire computer. But I also want to set up another Time Capsule (bus powered external hard drive) that will continually run as I work and only back up a single folder
-
Cant install PhotoSmart B109f on Windows Home Server 2011
Hi - Looking for help to get PhotoSmart B109f Printer installed on WHS2011 (64bit). I downloaded basic drivers for Win 7 64 bit and extracted the files from the exe. I went to device manager and used "Update Driver" to install the driver and the devi
-
Just tested with a very simple table called test_string with only one column "guid" (type varchar). Verification is OK, but always got the following error when deploying to server. Not sure about the reason. As it is a wrapException, is it possible t
-
How can I change the frame rate mode?
Adobe Premiere Pro exports my videos with a variable frame rate. Because of this long videos are asynchronous. How can i change the frame rate mode? So Adobe Premie Pro exports my videos with a CONSTANT frame rate? The original video has a constant
-
Photoshop cs3 quits unexpectedly
photoshop cs3 is quitting when i open images. if the images are over 500MB and i don't wait for the preview to open before opening it crashes immiadiatly. if i wait it doesn't crash straight away, but after opening two or three images it crashes. i