发送previous日文件服务器 [英] sending previous day file to server

查看:146
本文介绍了发送previous日文件服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已创建了简单的日期概念的文本文件。每天的文本文件将被存储我的那一天的日期系统。我送这些文本文件到服务器使用自动定时器的概念。

现在我的问题是,我想在previous一天的文本文件发送到服务器。对于例如:如果今天是周一,这里按我的计时器时间表在8,我需要周日的(previous日)的文本文件发送到服务器。我坚持在这里,我不知道如何实现这一点。
这里是我的编码

 文件MYDIR =新的文件(文件路径);
mydir.mkdirs();
最后字符串文件名=新的SimpleDateFormat(DD-MM-YYYY)格式(新的Date());
文件OUTPUTFILE =新的文件(MYDIR,文件名);
FOS的FileOutputStream =新的FileOutputStream(OUTPUTFILE,真);


解决方案

您需要定义一个服务,并使用处理程序应该从起始时间到8'O时钟的时间差异最初设置。那么计时器有限区间应在24小时内,在执行您可以发送文件...

例如:您在下午5点安装该应用程序,你需要首先发送的文件在晚上8点,所以你计算出间隔((8-5)* 60 * 60 * 60 * 1000),因为处理程序使用毫秒。之后,你可以将其设置为 24 * 60 * 60 * 60 * 1000

更新

使用处理这样的

 私人INT mInterval = 5000; //缺省为5秒,可在以后更改
私人处理器mHandler;@覆盖
保护无效的onCreate(捆绑包){    mHandler =新的处理程序();
}可运行mStatusChecker =新的Runnable(){
@覆盖
公共无效的run(){
  更新状态(); //这个功能可以改变mInterval的价值。
  mHandler.postDelayed(mStatusChecker,mInterval);
}
};无效startRepeatingTask(){
   mStatusChecker.run();
}无效申通快递prepeatingTask(){
   mHandler.removeCallbacks(mStatusChecker);
}

在这里,您需要更改的时间间隔为我刚才解释

I have created a text file with simple date concept. Everyday the textfile will be stored on my system with that day's date. I am sending these text files to the server automatically using timer concept.

Now my question is I would like to send the previous day's text file to the server. For ex: if today is monday, and here as per my timer schedule at 8, I need to send sunday's(previous day) text file to server. I am stuck here and I don't know how to achieve this. Here is my codings

File mydir = new File("file path");
mydir.mkdirs();
final String filename =   new SimpleDateFormat("dd-MM-yyyy").format(new Date());
File outputFile = new File(mydir, filename);
FileOutputStream fos = new FileOutputStream(outputFile,true);

解决方案

You need to define a service and use a handler which should initially set by the time difference from start time to 8'O clock. then the timer intervel should be 24 hours, Within the execution you can send the file...

Eg: you are installing the app at 5pm, you need to initially send the file at 8pm so you calculate the interval ((8-5) * 60 * 60 *60 * 1000) since handler use milliseconds. After that you can set it as 24 * 60 * 60 *60 * 1000

UPDATE

Use handler like this

private int mInterval = 5000; // 5 seconds by default, can be changed later
private Handler mHandler;

@Override
protected void onCreate(Bundle bundle) {

    mHandler = new Handler();
}

Runnable mStatusChecker = new Runnable() {
@Override 
public void run() {
  updateStatus(); //this function can change value of mInterval.
  mHandler.postDelayed(mStatusChecker, mInterval);
}
};

void startRepeatingTask() {
   mStatusChecker.run(); 
}

void stopRepeatingTask() {
   mHandler.removeCallbacks(mStatusChecker);
}

Here you need to change the interval as i explained earlier

这篇关于发送previous日文件服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆