Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在linux中设置路径?_Java_Linux_Struts2 - Fatal编程技术网

Java 如何在linux中设置路径?

Java 如何在linux中设置路径?,java,linux,struts2,Java,Linux,Struts2,我使用Struts2、java和mysql开发了一个web应用程序。当我在linux VM服务器上托管此应用程序时,它不工作。我认为这是由于一些路径问题 这是我的Java类: import com.altoopa.utils.DBConnection; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream;

我使用Struts2、java和mysql开发了一个web应用程序。当我在linux VM服务器上托管此应用程序时,它不工作。我认为这是由于一些路径问题

这是我的Java类:

import com.altoopa.utils.DBConnection;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
public class VideoBuffer {
    FileInputStream fis = null;
    FileOutputStream out = null;

            public String readVideo() throws IOException, SQLException {    
                    try {

             int i =0;
             String s=null;
               Date currentDate3 = Calendar.getInstance().getTime();
            System.out.println(currentDate3);
            int _day3 = currentDate3.getDay(); //Getting day
            System.out.println(_day3);
            String current_day3 = null;
            if (_day3 == 0) {
                current_day3 = "Redday";
            } else if (_day3 == 1) {
                current_day3 = "Violetday";
            } else if (_day3 == 2) {
                current_day3 = "Indigoday";
            } else if (_day3 == 3) {
                current_day3 = "Blueday";
            } else if (_day3 == 4) {
                current_day3 = "Greenday";
            } else if (_day3 == 5) {
                current_day3 = "Yellowday";
            } else if (_day3 == 6) {
                current_day3 = "Orangeday";
            }
            System.out.println(current_day3);
            Calendar cal3 = Calendar.getInstance();
            int week3 = cal3.get(Calendar.WEEK_OF_YEAR); //Getting week
            System.out.println(week3);

              DBConnection db=new DBConnection();
              Connection con=db.getDBConnection();
            String  query="SELECT calender_id FROM calender_altoopa WHERE week='" + week3 + "' and altoopa_day='" + current_day3 + "'";
          PreparedStatement ps=con.prepareStatement(query);
           ResultSet rs_scrc=ps.executeQuery();

            while (rs_scrc.next()) {

                 i = rs_scrc.getInt(1);
               System.out.println("calender iddfdsfdsfdsfsff"+i);

            }
            String query1="select video_name from sgbg_video where calender_id= ?";
             PreparedStatement ps1=con.prepareStatement(query1);
             ps1.setInt(1,i);
           ResultSet rs_scrc1=ps1.executeQuery();

            while (rs_scrc1.next()) {
                System.out.println(rs_scrc1.getString(1));
                 s=rs_scrc1.getString(1);
                 System.out.println("videoooooooooooo"+s);`enter code here`

            }
            fis = new FileInputStream(new File("D:\\Dk\\"+"\\"+s));

            String userImageFileName = "temp.mp4";
            out = new FileOutputStream(new File(
                    "D:\\sreejith_\\altoopa_6\\web\\VideoFile" + "\\"
                            +s));
            int c;
                        byte[] buffer=new byte[1024];
            while ((c = fis.read(buffer)) != -1) {
                System.out.println("Writing to file...");
                out.write(buffer,0,c);
            }
            out.flush();

            return s;
        }
                catch (Exception e) {
            e.printStackTrace();
        } finally {
            fis.close();
            out.close();
        }
        return null;
    }
}
使用这个类,我从D:Dk文件夹将视频文件流式传输到NeatBeans应用程序目录中的VideoFile文件夹中

我的问题是:我应该放置什么路径而不是“D:\Dk\”+“\”+s”来将应用程序部署到linux虚拟机上?我正在从这个目录中获取视频并放入
“D:\sreejith\uu\altoopa\u 6\web\VideoFile”+“+s))


URL重写过滤器
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
支柱2
org.apache.struts2.dispatcher.FilterDispatcher
支柱2``
30
文件上传路径
D:\Dk
音频上传路径
D:\AltoopaAudio
index.jsp

请帮助我如何将此应用程序部署到Linux上。

请查看代码中的硬编码文件路径(“D:\…”)。最好将其放到.properties文件或数据库表中,因为它们肯定不存在于Linux框中

编辑:

很抱歉,我可能不理解您的问题。您应该与运营商联系,为您的视频在Linux机箱中准备一个磁盘位置(可能是/视频,请记住Linux和Unix操作系统没有单位字母)


但这条路不是你的问题,你应该花一分钟来考虑你的需要。例如,你的应用程序是要投入生产吗?在这种情况下,你认为你需要多少空间?你的操作员肯定会告诉你他们需要一个准确的估计,因为VM盒的生产舱空间相当昂贵。在这种情况下,如果您的需求增长,您将如何确保可伸缩性(可能您需要准备某种NAS?

您应该在
web.xml
中更改配置,但这不适合多操作系统构建(当使用maven时,您需要配置激活,并拥有许多web.xml或在构建时转换它们)

IMO,更好的方法是配置系统变量并使用它们,如:

System.getenv("UP_FILE_PATH");
System.getenv("UP_VIDEO_PATH");

但最好的方法是在DB中创建配置表并将其放在那里。您的配置类中可能包含更多的方法,这些方法可以获取OS类型并从DB中读取正确的变量。

tnx。但是我在linux D,E..Drive中要求path.cause。我使用了D:\Dk。那么在linux中应该使用什么路径来代替它呢。/home/apphome/是一个很好的实践。Application Server以apphome用户的身份启动。Linux没有像
D:
这样的驱动器,并且\在文件路径中不是特殊字符(只有
/
是,但最好在文件路径中只使用字母、数字、下划线和点)…它有。
System.getenv("UP_FILE_PATH");
System.getenv("UP_VIDEO_PATH");