package com.studytrails.tutorials.springremotingrmiclient;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
public class call {
public String getText()
{
ApplicationContext appContext = new ClassPathXmlApplicationContext(new String[]{"spring-config-client.xml"});
StringBuilder builder = new StringBuilder();
//Resource resource = appContext.getResource("file:D:\\text\\test.txt");
Resource resource = appContext.getResource("file:D://text//test.txt");
try{
InputStream is = resource.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
File temp=File.createTempFile("output", ".tmp");
System.out.println("Accepted connection : ");
String filePath=temp.getAbsolutePath();
System.out.println(""+filePath);
String tem=temp.getName();
String line;
PrintWriter out = new PrintWriter(new FileWriter(tem));
while ((line = br.readLine()) != null) {
out.println(line);
}
out.close();
br.close();
temp.setReadOnly();
String[] cmd = {"notepad",tem};
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec(cmd);
Runtime.getRuntime().exec("cmd /c start \"%programfiles%\\Windows Media Player\\wmplayer.exe\" \"C:\\Users\\Public\\Videos\\Sample Videos\\Wildlife.wmv\"");
proc.getInputStream();
temp.deleteOnExit();
}catch(IOException e){
e.printStackTrace();
}
return builder.toString();
}
}
В приведенном выше коде на клиенте функция getText() считывает файл из локального каталога. Мне нужно загрузить файл с сервера компьютера для этого, что я могу сделать. я использую java весенние концепции для связи с сервером клиента. Возможны любые шансы загрузить ресурс в xml bean file.please post some use full codeПередача файла с использованием пружины
Используйте URL-адрес, чтобы загрузить файл. Это ваша домашняя работа? :) – Sho
Нет, это не домашнее задание. Я просто пытаюсь передать файл между двумя системами, используя весну. как это сделать с идентификатором bean. если у вас есть идея, пожалуйста, сообщите об этом. если вы хотите, я могу предоставить дополнительное кодирование, используемое в программе. – KVK